rstudio / pins-r

Pin, Discover and Share Resources
https://pins.rstudio.com
Other
301 stars 62 forks source link

pins doesnt seem to work with rocker / docker #812

Closed ncullen93 closed 7 months ago

ncullen93 commented 7 months ago

I am using rocker/verse in my docker file and when I try to load pins, it gives me the same error from https://github.com/rstudio/pins-r/issues/705

Error: package or namespace load failed for ‘pins’:
 .onLoad failed in loadNamespace() for 'pins', details:
  call: NULL
  error: [ENOENT] Failed to make directory '//.cache/pins': no such file or directory
Execution halted

I looked further and believe the error is from this function:

board_cache_path <- function(name) {
  # R_CONFIG_ACTIVE suggests we're in a production environment
  if (has_envvars("R_CONFIG_ACTIVE") || has_envvars("PINS_USE_CACHE")) {
    path <- fs::dir_create(tempdir(), "pins")
  } else if (has_envvars("PINS_CACHE_DIR") ) {
    path <- Sys.getenv("PINS_CACHE_DIR")
  } else {
    path <- cache_dir()
  }
  fs::path(path, name)
}

I guess rocker doesnt set R_CONFIG_ACTIVE so pins doesnt know it's in a production environment? In any case, setting R_CONFIG_ACTIVE as an environment variable in my heroku app makes the error go away.

Hard to make a reprex but basically the same reprex suggested in https://github.com/rstudio/pins-r/issues/705 gives the error when deployed .

juliasilge commented 7 months ago

Yes, it's true that the default mode for pins is set up for interactive work, and to use pins in an environment that is very limited in permissions or even read only, you need to set an environment variable to control the cache path. You can set R_CONFIG_ACTIVE like you found, or we document/recommend setting one of the environment variables that control where the pins cache is. For example from R, before loading the pins library, you could do something like:

Sys.setenv(PINS_CACHE_DIR = base::tempdir())
Sys.getenv("PINS_CACHE_DIR")
#> [1] "/var/folders/hv/hzsmmyk9393_m7q3nscx1slc0000gn/T//RtmpIFoEAQ"

Created on 2023-11-20 with reprex v2.0.2

Then you'd just have a per-session cache that writes to the temp directory only.

ncullen93 commented 7 months ago

Thanks!!

github-actions[bot] commented 7 months ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.