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

Persistent configuration files #3

Open
gaborcsardi opened this issue Jan 23, 2017 · 3 comments
Open

Persistent configuration files #3

gaborcsardi opened this issue Jan 23, 2017 · 3 comments

Comments

@gaborcsardi
Copy link

Via https://github.com/hadley/rappdirs? So that a config file survives the re-install of a package or project.

I am not sure if this is in the scope of config, just an idea. I am also not sure how it would work together with the current mechanism of looking for the config file in the parent directories.

@jimhester
Copy link
Contributor

FWIW I think this is a good suggestion. Another idea would be to have the fallback in the home directory, possibly prefixed with .. I think we could support all of them by looking for values in the following order

  1. Current working directory
  2. Parent directories
  3. Application directories
  4. Home directory

Something like

fallback <- function(..., appname, file = "config.yml", use_parent = TRUE) {
  res <- tryCatch(config::get(..., file = file, use_parent = use_parent), error = function(e) NULL)

  if (!is.null(res)) {
    return(res)
  }
  for (file_path in c(
      file.path(rappdirs::user_config_dir(appname), file),
      file.path(Sys.getenv("HOME"), paste0(".", file)))) {
    res <- tryCatch(config::get(..., file = file_path, use_parent = FALSE), error = function(e) NULL)
    if (!is.null(res)) {
      return(res)
    }
  }
  NULL
}

@gaborcsardi
Copy link
Author

The user's application directories are already in the home directory, so I would personally omit 4.

rappdirs::user_log_dir(os = "unix")
[1] "/Users/gaborcsardi/.cache/log"rappdirs::user_data_dir(os = "unix")
[1] "/Users/gaborcsardi/.local/share"rappdirs::user_config_dir(os = "unix")
[1] "/Users/gaborcsardi/.config"rappdirs::user_cache_dir(os = "unix")
[1] "/Users/gaborcsardi/.cache"

@gaborcsardi
Copy link
Author

Btw. 4. is probably also included in 2...

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