Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad formatting when passing bare lubdridate dates #665

Closed
DanChaltiel opened this issue Jan 17, 2024 · 4 comments
Closed

Bad formatting when passing bare lubdridate dates #665

DanChaltiel opened this issue Jan 17, 2024 · 4 comments

Comments

@DanChaltiel
Copy link
Contributor

DanChaltiel commented Jan 17, 2024

Hi,

Here is a very minor bug that happens when passing bare dates to cli.
An easy workaround is wrapping the value in curly braces.

Here is a reprex with cli_warn():

x = lubridate::today()
#or x = base::Sys.Date()
cli::cli_warn(x)
#> Warning: 19739
cli::cli_warn(c("foobar", i=x))
#> Warning: foobar
#> i 19739
cli::cli_warn("{x}")
#> Warning: 2024-01-17

Created on 2024-01-17 with reprex v2.0.2

@DanChaltiel DanChaltiel changed the title Bad formatting when passing bare dates Bad formatting when passing bare lubdridate dates Jan 17, 2024
@gaborcsardi
Copy link
Member

Maybe we could fix this, but in general you should always pass string literals to cli functions.

@DanChaltiel
Copy link
Contributor Author

Then, maybe a simple stopifnot(is.character(message)) would solve the problem? Or parsing message as character?

@gaborcsardi
Copy link
Member

I don't mean a character object, I mean a literal. I.e. not

x <- "foobar"
cli_text(x)

but

cli_text("foobar")

Btw. c("foobar", i=x) is not a date any more, so there is no way to recover from that:

❯ c("foobar", i = x)
                i 
"foobar"  "19739" 

@DanChaltiel
Copy link
Contributor Author

Oh yes, of course it is not a date anymore, how could I miss that!

OK, I get it, this makes perfect sense.
Indeed, I don't think I ever really use cli without a literal, this just happened during debugging (yes, I shamelessly use cli as a debug printer).

Parsing message to character seems to solve the initial date problem (which is not limited to lubridate as I initially thought).

BTW, I am surprised that all objects are allowed and printed bare:

x = lm(1~1)
cli::cli_warn(x) #cli_text wraps it
#> Warning: 1
#> 0
#> 1
#> 1
#> 1
#> 0
#> 1111e-071
#> 0
#> lm(formula = 1 ~ 1)
#> 1 ~ 1
#> 1

Created on 2024-01-17 with reprex v2.0.2

Mostly, cli::cli_text(iris) would print the whole dataset, which would crash my console if run by error with a very large table. But I'm drifting out of the scope of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants