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

cli_alter_* with cat(), symbols positioned at end of output #707

Closed
eli-daniels opened this issue Jul 24, 2024 · 4 comments
Closed

cli_alter_* with cat(), symbols positioned at end of output #707

eli-daniels opened this issue Jul 24, 2024 · 4 comments

Comments

@eli-daniels
Copy link

Hello,
Thanks for a very cool package! I ran into this issue when combining cat() with cli_alert_* functions.

I would have expected the ouputs of following two code chunks to be the same:

> cli::cli_alert_danger('hello you')
✖ hello you
> cli::cli_alert_danger(cat( 'hello',  'you' ))
hello you

But the ✖ is in the wrong position in the second case.

@gaborcsardi
Copy link
Member

I am not sure why you expected that. cat() prints the text and returns NULL before cli::cli_alert_danger() is even called. So I am not sure how cli_alert_danger() could do anything differently here.

❯ print(cat( 'hello',  'you' ))
hello youNULL

@eli-daniels
Copy link
Author

Okay, I probably just don't really understand what cat() does. I'm getting my intended output by replacing it with paste().
Anyway, thanks for your help!

@gaborcsardi
Copy link
Member

cat() prints to the screen (by default) and does not return anything:

x <- cat("foo", "bar")
foo barx
NULL

@eli-daniels
Copy link
Author

Right, so the strings are printed directly to console by cat() which returns NULL to cli_alert_* which only then prints the symbol. Got it, thanks!

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