pins-r icon indicating copy to clipboard operation
pins-r copied to clipboard

Error: package or namespace load failed for ‘pins’ on huggingface

Open F041 opened this issue 11 months ago • 1 comments

I have this useless-toy model on HF: https://huggingface.co/spaces/vesorit/InflazioneItalia on posit cloud, it gives a problem in another stage, something that the wonderful @juliasilge already showed here: https://stackoverflow.com/questions/71397075/why-does-deploying-a-tidymodel-with-vetiver-throw-a-error-when-theres-a-variabl

on HF instead, I get:

> pr <- plumber::plumb('/opt/ml/plumber.R'); pr$run(host = '0.0.0.0', port = 8000)
Error in stopOnLine(lineNum, file[lineNum], e) : 
  Error on line rstudio/vetiver-r#2: '' - 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
Calls: <Anonymous> ... tryCatchList -> tryCatchOne -> <Anonymous> -> stopOnLine
Execution halted

Following https://github.com/rstudio/pins-r/issues/705 didn't help

F041 avatar Mar 05 '24 13:03 F041

Check out this documentation for managing the cache on read-only systems:

https://pins.rstudio.com/reference/board_cache_path.html#details

You'll need to use an env var to make sure the cache path is somewhere writable, like base::tempdir().

juliasilge avatar Mar 05 '24 18:03 juliasilge

Let us know if you have further questions! 🙌

juliasilge avatar Apr 29 '24 17:04 juliasilge

sorry, I took some time to go through it but I have no idea how to implement it for example in this chunk

model_board <- board_folder(path = "pins-r", versioned = TRUE)
model_board |> vetiver_pin_write(v)
model_board |>
  vetiver::vetiver_write_plumber("uk-edu-rf")
write_board_manifest(model_board)
board_cache_path(model_board)


vetiver_write_docker(v,plumber_file = "plumber.R",lockfile = "vetiver_renv.lock")

F041 avatar May 03 '24 09:05 F041

You'll want to set an environment variable to control where the board cache goes. From R, you set an env var with Sys.setenv():

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

Created on 2024-05-03 with reprex v2.1.0

You can set the env var like this:

Sys.setenv(PINS_CACHE_DIR = base::tempdir())
library(pins)
board <- board_folder("~/Downloads/")
board_cache_path(board)
#> /var/folders/hv/hzsmmyk9393_m7q3nscx1slc0000gn/T/Rtmpzxh6pl/pins_board_folder
#> /var/folders/hv/hzsmmyk9393_m7q3nscx1slc0000gn/T/Rtmpzxh6pl/1
#> NA
#> /var/folders/hv/hzsmmyk9393_m7q3nscx1slc0000gn/T/Rtmpzxh6pl/FALSE
#> /var/folders/hv/hzsmmyk9393_m7q3nscx1slc0000gn/T/Rtmpzxh6pl/~/Downloads

Created on 2024-05-03 with reprex v2.1.0

Or you can set it generally using a non-R tool.

juliasilge avatar May 03 '24 16:05 juliasilge

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.

github-actions[bot] avatar May 18 '24 00:05 github-actions[bot]