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

Allow hashtags in single-line input strings #193

Closed
gadenbuie opened this issue Jun 4, 2020 · 1 comment
Closed

Allow hashtags in single-line input strings #193

gadenbuie opened this issue Jun 4, 2020 · 1 comment

Comments

@gadenbuie
Copy link

I've been playing with something akin to the collapse_transformer() example, but I'd like to be able to include # in one-line input strings.

What I want to do is essentially the following, where I would parse the template string in the transformer, but unfortunately it doesn't make it past the parser.

glue::glue("{#b a}")
# no output due to #b

Here are a few examples using an identity transformer that just returns the text that reaches the transformer.

identity <- function(x, ...) x

glue::glue("{a}", .transformer = identity)
#> a

"{a*}" works and the transformer receives "a*", but "{a#}" does not work: the transformer isn’t called …

glue::glue("{a*}", .transformer = identity)
#> a*
glue::glue("{a#}", .transformer = identity)

…unless the # is followed by a new line.

glue::glue("{a#\n}", .transformer = identity)
#> a#

Another example without the identity transformer.

a <- "apple"
glue::glue("{a#}")
glue::glue("{a#\n}")
#> apple

I can see where problems could arise with incomplete expressions due to comments, but it also makes sense that such problems would throw parsing errors.

glue::glue("{c(a,#\na)}")
#> apple
#> apple
glue::glue("{c(a,#a)}")
glue::glue("{c(a,#a)\n}")
#> Error in parse(text = text, keep.source = FALSE): <text>:3:0: unexpected end of input
#> 1: c(a,#a)
#> 2: 
#>   ^

That said, one place where changing the parser might break current behavior is that currently empty expressions cause the entire result to be zero-length. Except for the last, the following all return character(0).

glue::glue("{#a} {'banana'}")
glue::glue("{#a\n} {'banana'}")
glue::glue("{a#a} {'banana'}")
glue::glue("{a#a\n} {'banana'}")
#> apple banana

Created on 2020-06-04 by the reprex package (v0.3.0)

gadenbuie added a commit to gadenbuie/epoxy that referenced this issue Jun 4, 2020
Fixes #3

Uses % instead of # for id markup, see: tidyverse/glue#193
@jimhester
Copy link
Collaborator

You can now control the comment character with the .comment argument, so what you are trying to do should now be possible.

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