-
Notifications
You must be signed in to change notification settings - Fork 129
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
cache$destroy deletes entire directory #926
Comments
Sorry to hear that.
There is probably a cache in a parent directory. By default,
Odd, that should not happen. When you set up your project, what does
Sorry, this is not enough information to reproduce what you are seeing. It is missing the steps to define |
Hi Will, Sorry, I was kind of in a rush when I submitted this issue. I apologize. I'm editing the reprex above to correctly reproduce the error. TL/DR: the users may not be aware of the behavior of how Drake's cache is created/destroyed and may suffer side effects from their lack of knowledge/attention. I am now aware of what exactly happened. Not sure however if something must be done about it. I was using the library Unfortunately, that does not happen. Drakes uses the exact folder that was given in the This can be very dangerous if the user does not specify an exclusive folder for the Drake cache. For beginners, the manual mentions on a brief passage how to delete the cache, but as it is, it appears that While this now seems obvious to me, given the potential destructive behavior of the function |
Thanks, I did not realize this was a problem. So then was the path of the cache really the same as the root of the project? How exactly were you creating the cache? There are a couple ways we could handle this, but before I implement something, it would help to see the code you were using to set up the cache and call make(). |
In the first example. Let me explain what I did. The So, let's suppose my project folder is located on
So, to access the data directory to read some file, I just have to use When I was creating the drake cache trying to follow your suggestion on #907, I inadvertently used the line I then created my plan: library(here)
library(drake)
cache <- storr::storr_rds(here(), compress = FALSE)
plan <- drake_plan(temp = matrix(runif(10^3), ncol = 5))
config <- drake_config(plan,
cache_log_file = "cache_log.csv",
verbose = 2,
garbage_collection = T,
retries = 2,
lock_envir = FALSE,
cache = cache
)
make(config = config) Drake created other subdirectories:
And then, finally, when I ran The Drake step doesn't really matter, because everything is being managed by the An example would be: delete_cache <- function() {
library(storr)
drake_path <- dir(pattern = "\\.drake", recursive = TRUE, all.files = T, include.dirs = T)
if (length(drake_path) == 0) {
stop("Cache not found.")
}
cache <- storr::storr_rds(paste0(getwd(), "/", drake_path), compress = FALSE) # not sure if this destroys the cache created
# by make - it is just a sketch
cache$destroy()
}
# Using the here package
delete_cache <- function() {
library(storr)
library(here)
setwd(here())
drake_path <- dir(pattern = "\\.drake", recursive = TRUE, all.files = T, include.dirs = T)
if (length(drake_path) == 0) {
stop("Cache not found.")
}
cache <- storr::storr_rds(paste0(here(), "/", drake_path), compress = FALSE)
cache$destroy()
} |
Thanks. I think it is enough for |
Prework
drake
's code of conduct.Description
Trying to understand better what happened at #925, I decided to remove the whole cache of my Drake plan. Strangely, even after the removal of the cache, when I tried to generate a visualization of the plan there were some steps of the plan that were up to date (green).
Wishing to remove all those targets, I re-run
cache$destroy()
. That had the side effect of permanently deleting all files in the current working directory, including datasets and code scripts. I'm unsure exactly why this was the case.I think that what has probably happened is that
find_cache()
or some similar function to return the path to the drake cache returnedNULL
and some kind of command such asrm
delete permanently all the files in the current working directory.This, of course, is giving me some extensive headache to recover the most updated code files from my project. I think some kind of warning or check before destroying the cache should be in place, such as
if(is.null(find_cache())){stop("Cache was not found.")}
to avoid this kind of problem.Reproducible example
Expected output
Drake would not have removed files not related to Drake's cache.
The text was updated successfully, but these errors were encountered: