ropensci / rdryad

R client for Dryad web services
https://docs.ropensci.org/rdryad
Other
25 stars 7 forks source link

rdryad_cache as option rather than global var #36

Closed mpadge closed 2 years ago

mpadge commented 2 years ago

@sckott I presume you won't be looking at this, but ping nonetheless just in case. I'll give you a couple of days, otherwise i'll merge by end of week regardless.

Description

@trashbirdecology @krzbar Hi there, I've taken over maintenance of this package now. This PR implements an ability to specify the cache directory used by rdryad. Functionality demonstrated in the reprex below.

The previous version used the .onLoad line dryad_cache <<- <...>. As well as the problems identified in #34, #35, that failed in many places anyway, notably including calls embedded within other processes or threads. This PR stores the hoardr object specifying the cache in options(), which are faithfully copied and passed between all callr processes, so this approach should be more robust.

Related Issue

Fixes #34 Fixes #35

Example

library (rdryad)
rdryad_cache <- rdryad::dryad_get_cache ()
rdryad_cache$cache_path_set (full_path = normalizePath ("~/Downloads/junk", mustWork = FALSE))
#> [1] "/home/me/Downloads/junk"
# mustWork = F because path does not (yet) exist
rdryad_cache$cache_path_get ()
#> [1] "/home/me/Downloads/junk"
rdryad_cache$mkdir()
rdryad::dryad_set_cache (rdryad_cache)
dryad_download(dois = "10.5061/dryad.f385721n")
#> $`10.5061/dryad.f385721n`
#> [1] "/home/me/Downloads/junk/10_5061_dryad_f385721n/Crossin et al 2012 MAC data for Dryad.csv"           
#> [2] "/home/me/Downloads/junk/10_5061_dryad_f385721n/README_for_Crossin et al 2012 MAC data for Dryad.rtf"

Created on 2021-11-09 by the reprex package (v2.0.1.9000)

sckott commented 2 years ago

LGTM mark

trashbirdecology commented 2 years ago

Thanks for addressing this suggestion. Unfortunately I don't have time to push any reprex, but it looks like someone might already be on top of it!