rstudio / pins-r

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

Downloading RData file from pin to working directory #757

Closed mubashirqasim closed 11 months ago

mubashirqasim commented 1 year ago

First of all, thank you very much for a great R package. It works seamlessly with Azure, Connect and other services.

I have a hard time downloading the RData file from a Posit Connect pin. None of my solutions in the following example are working. Any thoughts on how to fix this?

library(pins)
library(rsconnect)

board <- board_connect()

data("mtcars")
data("iris")
data("airquality")

# Save Environment as RData
save.image("ShinyApp_input_data.RData", compress = TRUE)

## Upload RData
board %>% pin_upload(name = "ShinyApp_input_data", paths = "ShinyApp_input_data.RData")

# Download/load RData
path <- board %>% pin_download(name = "ShinyApp_input_data")
load(path)

# My attempts to download RData to working directory
board %>% pin_download(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)
board %>% pin_get(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)
board %>% pin_read(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)
board %>% pin_fetch(name = "ShinyApp_input_data", local_path = "ShinyApp_input_data.RData", overwrite = TRUE)

PS: In a ShinyApp, it is possible to use ShinyApp_input_data.RData as a default option and download new data from pin only if it has been updated. In that case, download the updated data from pin and replace the local RData file in the project directory.

juliasilge commented 1 year ago

I may not be entirely understanding the details of your problem, but here is one approach that works for me, similar to what is outlined in this vignette. First I write a pin:

library(pins)
board <- board_connect()
#> Connecting to Posit Connect 2023.05.0 at <https://colorado.posit.co/rsc>
data("mtcars")
data("iris")
data("airquality")
save.image("test-rdata-pin.RData", compress = TRUE)
board |> pin_upload("test-rdata-env", paths = "test-rdata-pin.RData")

Created on 2023-07-07 with reprex v2.0.2

And then in a new session I can read that pin and the objects in the environment are there:

library(pins)
board <- board_connect()
#> Connecting to Posit Connect 2023.05.0 at <https://colorado.posit.co/rsc>
board |> pin_download(name = "julia.silge/test-rdata-env") |> load()
ls()
#> [1] "airquality" "board"      "iris"       "mtcars"

Created on 2023-07-07 with reprex v2.0.2

Are you asking about getting the file into the working directory? I would probably use something like fs::fs_copy() for that.

juliasilge commented 11 months ago

Let us know if you have further questions!

mubashirqasim commented 11 months ago

Thanks Julia, that helps!

github-actions[bot] commented 11 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.