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

Determine nonstandard cache location from within make() #1167

Closed
2 of 3 tasks
brendanf opened this issue Feb 11, 2020 · 3 comments
Closed
2 of 3 tasks

Determine nonstandard cache location from within make() #1167

brendanf opened this issue Feb 11, 2020 · 3 comments

Comments

@brendanf
Copy link
Contributor

Prework

  • Read and abide by drake's code of conduct.
  • Search for duplicates among the existing issues, both open and closed.
  • If you think your question has a quick and definite answer, consider posting to Stack Overflow under the drake-r-package tag. (If you anticipate extended follow-up and discussion, you are already in the right place!)

Question

Is there a way to determine from inside target code what the location of the drake cache used in the current make invocation is?

library(drake)
cache2 <- new_cache(".cache2")
plan <- drake_plan(x = 1, y = readd(x))

make(plan, memory_strategy = "none", cache = cache2)
## target x
## target y
## fail y
## Error: Target `y` failed. Call `diagnose(y)` for details. Error message:
##  key 'x' ('objects') not found

Of course it can be passed explicitly from outside, but it would be nice to be able to specify "readd from whatever cache make is currently using".

@wlandau
Copy link
Member

wlandau commented Feb 12, 2020

I would actually prefer to limit automatic cache detection. Searching for the default .drake/ folder from readd() is usually fine because it is clear what drake is doing, but as soon as people start creating their own caches, we need to worry about situations where people create multiple caches side by side, to say nothing of alternative storr backends like storr_dbi().

Even with the default .drake folder, it is dangerous to recurse upwards in make(). I regret this feature of make(), which is why I plan to remove it next time I have an excuse for a round of breaking changes, re #919. Related:

drake/R/make.R

Lines 570 to 582 in 8004f4c

"Running make() in a subdirectory of your project. \n",
"This could cause problems if your ",
"file_in()/file_out()/knitr_in() files ",
"are relative paths.\n",
"Please either\n",
" (1) run make() from your drake project root, or\n",
" (2) create a cache in your working ",
"directory with new_cache('path_name'), or\n",
" (3) supply a cache of your own (e.g. make(cache = your_cache))\n",
" whose folder name is not '.drake'.\n",
" running make() from: ", wd, "\n",
" drake project root: ", dir, "\n",
" cache directory: ", config$cache$path,

@wlandau wlandau closed this as completed Feb 12, 2020
@brendanf
Copy link
Contributor Author

If I understand correctly, then the only solution when using make(memory_strategy = "none", cache = my_cache) is to explicitly code it into every readd in the plan?

library(drake)
plan <- drake_plan(x = 1, y = readd(x, cache = ignore(my_cache)))

my_cache <- new_cache(".my_cache")
make(plan, memory_strategy = "none", cache = my_cache)

@wlandau
Copy link
Member

wlandau commented Feb 12, 2020

Or wrap readd() in your own function.

my_cache <- new_cache(".my_cache")
rdd <- function(...) readd(..., cache = my_cache)

NB the latest drake should now automatically ignore() caches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants