rstudio / renv

renv: Project environments for R.
https://rstudio.github.io/renv/
MIT License
971 stars 152 forks source link

`renv::install()` sometimes doesn't like `glue::glue()` double curly brace escapes #1891

Open pbbgss opened 1 month ago

pbbgss commented 1 month ago

Hello there!

Since version 1.0.0 (I think) renv appears to have a problem with the use of {{}} in glue::glue() expressions where there is a variable to be evaluated inside the escaped braces. (A use case for these is when dynamically building {cli} formatted messages).

Reprex (using {renv} 1.0.7)

writeLines("Imports:\n\tglue\n\tcli", con = "DESCRIPTION")

# This will cause issues
writeLines("foo <- 'world'\nbar <- glue::glue('Hello {{{foo}}}')", con = "foo.R")

# This will cause issues - this is the "real" use case with a cli class
writeLines("foo <- 'world'\nbar <- glue::glue('Hello {{.strong {foo}}}')", con = "bar.R")

# This will not cause issues
writeLines("foo <- 'world'\nbar <- glue::glue('Hello {foo}')", con = "baz.R")

# This will not cause issues
writeLines("foo <- 'world'\nbar <- glue::glue('Hello {{world}}')", con = "ham.R")

renv::install()
WARNING: One or more problems were discovered while enumerating dependencies.

# /home/pbbgss/projects/foo/bar.R --------------------------------------------
Error: <text>:1:4: unexpected '}'
1: foo}
       ^

# /home/pbbgss/projects/foo/foo.R --------------------------------------------
Error: <text>:1:4: unexpected '}'
1: foo}
       ^

Please see `?renv::dependencies` for more information.

The warning isn't triggered on {renv} 0.15.4 but I haven't tested everything in between