-
Notifications
You must be signed in to change notification settings - Fork 133
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
golem::document_and_reload is not using get_golem_config to figure out where the golem configuration is #887
Comments
Hi @harell, Thanks for reporting this. TLDR: Currently you cannot change the location of Indeed, despite the comment in the code of # Modify this if your config file is somewhere else
file = app_sys("config/golem-config.yml") It is not currently possible to change the location of the Doing so will break a number of golem functions that rely on
In current Here is a reprex of that issue: # Using golem last dev version
packageVersion("golem")
#> [1] '0.3.2.9004'
path_dummy_golem <- tempfile(pattern = "dummygolem")
golem::create_golem(
path = path_dummy_golem,
open = FALSE
)
#> ── Checking package name ───────────────────────────────────────────────────────
#> ✔ Valid package name
#> ── Creating dir ────────────────────────────────────────────────────────────────
#> ✔ Creating '/tmp/RtmpFJejPj/dummygolem74271f138c71/'
#> ✔ Setting active project to '/tmp/RtmpFJejPj/dummygolem74271f138c71'
#> ✔ Creating 'R/'
#> ✔ Writing a sentinel file '.here'
#> • Build robust paths within your project via `here::here()`
#> • Learn more at <https://here.r-lib.org/>
#> ✔ Setting active project to '<no active project>'
#> ✔ Created package directory
#> ── Copying package skeleton ────────────────────────────────────────────────────
#> ✔ Copied app skeleton
#> ── Setting the default config ──────────────────────────────────────────────────
#> ✔ Configured app
#> ── Running project hook function ───────────────────────────────────────────────
#> ✔ All set
#> ✔ Setting active project to '/tmp/RtmpFJejPj/dummygolem74271f138c71'
#> ── Done ────────────────────────────────────────────────────────────────────────
#> A new golem named dummygolem74271f138c71 was created at /tmp/RtmpFJejPj/dummygolem74271f138c71 .
#> To continue working on your app, start editing the 01_start.R file.
old_wd <- setwd(path_dummy_golem)
# Works fine
golem::document_and_reload()
#> Setting `RoxygenNote` to "7.2.0"
#> ℹ Loading dummygolem74271f138c71
#> Writing 'run_app.Rd'
#> ℹ Loading dummygolem74271f138c71
# Move config file
dir.create(
"inst/config"
)
file.copy(
from = "inst/golem-config.yml",
to = "inst/config/golem-config.yml"
)
#> [1] TRUE
file.remove(
"inst/golem-config.yml"
)
#> [1] TRUE
# {golem} cannot find golem-config.yml
golem::document_and_reload()
#> Error in get_current_config(path, set_options = TRUE): The golem-config.yml file doesn't exist.
# Edit R/app_config.R won't help
path_app_config <- "R/app_config.R"
writeLines(
sub(
pattern = "golem-config\\.yml",
replacement = "config/golem-config.yml",
readLines(path_app_config)
),
path_app_config
)
pkgload::load_all()
#> ℹ Loading dummygolem74271f138c71
golem::document_and_reload()
#> Error in get_current_config(path, set_options = TRUE): The golem-config.yml file doesn't exist.
# The error is triggered by which remains agnostic
# of the change in location of golem-config.yml
golem::get_golem_wd()
#> Error in get_current_config(path, set_options = TRUE): The golem-config.yml file doesn't exist.
# This will also also append with other functions trying to
# access golem-config.yml
golem::get_golem_name()
#> Error in get_current_config(path, set_options = TRUE): The golem-config.yml file doesn't exist.
## The main culprit is golem:::get_current_config() (internal function)
# Where the path to "golem-config.yml" is hardcoded to "inst/golem-config.yml"
golem:::get_current_config()
#> Error in golem:::get_current_config(): The golem-config.yml file doesn't exist. |
@ColinFay I started working on a fix in branch |
@ALanguillaume are you still planning on working on this? |
Whenever So Currently, the user is asked to make changes to the location of the config-yaml in “R/app_config.R” # Modify this if your config file is somewhere else
file = app_sys("config/golem.yml") So that’s currently the best place for Sorry for the prior mess in the now closed PR, but #1043 could be considered instead now. |
Here is the current workaround :
Just so you know, the get_golem_wd() function relying on a config.yaml file is a CRAN requirement, bcs you can't manipulate the user dir without giving explicit notice & allowing to change it. I'm currently torn about this, I'm not sure we would want to support changing where the config file is stored, given that, by definition, it's the config file and that moving it would require to hard write the location somewhere else 🤔 Just like you need the Another option would be to have an env var then defaulting to the current heuristic that looks for the file, but I feel like it adds a bit of complexity. Happy to have your feedbacks about this. |
Hi @ColinFay I understand your point and having configs randomly flying in some folders is certainly unwise and not support good dev practices.. I have a feeling, though, that being able to have
gives extra freedom in switching configs quickly for dev/prod setups. It's possible to hard-code the top-level path and having clear error messages when there is no config at all, or if the exact file name cannot be found? Happy to make a change to my back then PR if you like |
Hi
Thanks for the great work.
Given I have moved the default "./inst/golem-config.yml" to "./inst/config/golem.yml"
AND declare the configuration file path in "/R/get_golem_config.R"
When I run "./dev/run_dev.R"
Then script fails to find the config file in the updated address
Failure Message
get_golem_config
Note I updated
file = app_sys("config/golem.yml")
from its originalfile = app_sys("golem-config.yml")
Failure Traceback
get_golem_config
to retrieve information from the configuration file.Please advise how to change the location of the yml file and run
/run_dev.R
successfully.The text was updated successfully, but these errors were encountered: