rstudio / config

config package for R
https://rstudio.github.io/config/
256 stars 27 forks source link

Unable to use R expression for inheritance #38

Closed RoelVerbelen closed 1 year ago

RoelVerbelen commented 3 years ago

Thanks for building this great package!

I notice that using an R expression for the inherits field is currently not allowed:

shinyapps:
  inherits: !expr Sys.getenv("CONFIG")
  driver: 'PostgreSQL'

triggers an error for these lines of do_get():

Error in match(x, table, nomatch = 0L) : 
  'match' requires vector arguments

Context: Trying to use the config package to manage multiple shinyapps deployments (using different config settings for the application). I am exploring a setup in which I can specify the config setting of choice using an environment variable "CONFIG", but when deploying the shiny app to shinyapps.io I need to overwrite the driver setting (keeping all rest in occordance to selected config settings).

Current workaround for my use case is to rather do something like this:

default:
  driver: !expr if ( Sys.getenv("R_CONFIG_ACTIVE") == "shinyapps" ) 'PostgreSQL' else 'PostgreSQL Unicode(x64)'
andrie commented 2 years ago

Thanks for investigating. I believe this is a duplicate of #9 and may be fixed by #36.

andrie commented 1 year ago

Closing, since this was (probably) fixed in #36. Please re-open with additional comments if there is more work to be done here.

RoelVerbelen commented 1 year ago

Hi @andrie

Thanks for the update. I just installed the latest version 0.3.2 in which I don't believe this issue is resolved. Here's a mininal example:

Define test.yml as

default:
  letter: 'a'

b:
  letter: 'b'

shinyapps:
  inherits: !expr Sys.getenv("CONFIG")

and then run

Sys.setenv("CONFIG" = "b")
config::get(file = "test.yml", config = "shinyapps")
Error in match(x, table, nomatch = 0L) : 
  'match' requires vector arguments
andrie commented 1 year ago

Thank you, that's helpful.

I've pushed a potential fix to the dev branch. Can you please check out the dev branch and tell me if it works for you?

RoelVerbelen commented 1 year ago

That seems to have done the trick:

remotes::install_github("rstudio/config", ref = "dev")
Sys.setenv("CONFIG" = "b")
config::get(file = "test.yml", config = "shinyapps")
$letter
[1] "b"

$inherits
[1] "b"
andrie commented 1 year ago

Thank you. I've now merged this into the main branch.

RoelVerbelen commented 1 year ago

Thanks a lot!