-
Notifications
You must be signed in to change notification settings - Fork 64
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
all output lost when using if statement without else in glue #266
Comments
I guess also the same is observed from an empty glue statement, for example. stuff + glue(). I guess my expected behavior would be to return stuff, not nothing. |
One might say that, on your first example, if there is no "you", then there is no need to say "Hello" to anyone, and therefore the original example, labelled as "This fails" is actually consistent 🤯 😃 . I guess that's the reason why glue behaves the way it does. I'm no glue expert, so I will try to understand a few things:
So, a workaround that returns what you expect can be obtained using the
I hope this helps. |
Ok - that helps. I guess in your example, if you say "hello" in the woods and no one is around to hear it, you didnt actually say "hello"? In the documentation for glue it states: .null | [character(1): ‘character()’]Value to replace NULL values with. If character() whole output is character(). If NULL all NULL values are dropped (as in paste0()). Otherwise the value is replaced by the value of .null. However, if you compare the output of paste0 and glue, the answer is not consistent.
glue::glue(NULL, "hello", .null = NULL) I guess the documentation says that the default is character(). So the addition of glue(character()) + glue("hello") is an empty glue string? My question is: shouldn't this behave consistent with paste0? |
I believe I'm also getting bit by this, maybe the x = 1
glue("{x} {x}")
# 1 1
glue("{x} {}") # nothing printed, not immediately clear why
glue("X} {}")
Error in eval(parse(text = text, keep.source = FALSE), envir) :
object 'X' not found |
Very minimal reprex: glue::as_glue(character()) Created on 2023-01-25 with reprex v2.0.2 (And switching to In terms of consistency, I think the main problems are described in #246 |
And printing is now in #290, so I'm going to close this issue. |
Hi,
I was using an if statement in glue, and ran across something that I think this is not the intended behavior?
If I use an if statement without specifying the else (FALSE) condition, all output is lost. I am not sure if this is a bug, but it was not the behavior I was expecting. In the case that the else statement is not specified, it doesn't matter what is present in any other number of glue() statement, the combined glue string is empty.
I expected that the glue string when no else case was specified would return an empty string, and let me combine multiple if statements in sequence, without specifying the else.
Thanks!
The text was updated successfully, but these errors were encountered: