簡體   English   中英

共享驅動器上帶有Drake的文件路徑

[英]File paths with drake on a shared drive

我遇到一些奇怪的德雷克行為,但我無法弄清楚。 我正在嘗試將.rmd添加到我的.rmd計划中。 我正在遠程計算機上以及該計算機上的網絡驅動器上工作。 如果我嘗試將.rmd文件添加到我的計划中,如下所示:

> library(drake)
> library(rmarkdown)
> 
> list.files()
[1] "drake_testing.Rproj"        "foo.png"             "report.Rmd"                    
> 
> plan <- drake_plan(
+   png("foo.png"),
+   plot(iris$Sepal.Length ~ iris$Sepal.Width),
+   dev.off(),
+   report = render(
+     input = knitr_in("report.Rmd"),
+     output_file = "report.html",
+     quiet = TRUE
+   )
+   
+ )
> 
> plan
# A tibble: 4 x 2
  target         command                                                                               
  <chr>          <expr>                                                                                
1 drake_target_1 png("foo.png")                                                                        
2 drake_target_2 plot(iris$Sepal.Length ~ iris$Sepal.Width)                                            
3 drake_target_3 dev.off()                                                                             
4 report         render(input = knitr_in("report.Rmd"), output_file = "report.html",      quiet = TRUE)
> 
> ## Turn your plan into a set of instructions
> config <- drake_config(plan)
Error: The specified file is not readable: report.Rmd
> 
> traceback()
13: stop(txt, obj, call. = FALSE)
12: .errorhandler("The specified file is not readable: ", object, 
        mode = errormode)
11: digest::digest(object = file, algo = config$hash_algorithm, file = TRUE, 
        serialize = FALSE)
10: rehash_file(file, config)
9: rehash_storage(target = target, file = file, config = config)
8: FUN(X[[i]], ...)
7: lapply(X = X, FUN = FUN, ...)
6: weak_mclapply(X = keys, FUN = FUN, mc.cores = jobs, ...)
5: lightly_parallelize_atomic(X = X, FUN = FUN, jobs = jobs, ...)
4: lightly_parallelize(X = knitr_files, FUN = storage_hash, jobs = config$jobs, 
       config = config)
3: cdl_get_knitr_hash(config)
2: create_drake_layout(plan = plan, envir = envir, verbose = verbose, 
       jobs = jobs_preprocess, console_log_file = console_log_file, 
       trigger = trigger, cache = cache)
1: drake_config(plan)

我嘗試了以下排列以使其工作:

  • .rmd移動到本地驅動器,並使用完整路徑調用它
  • file.path內外添加knitr_in以完成完整路徑。
  • 嘗試針對上述每種情況使用file_in

我也嘗試過調試,但是當drake將文件名轉換為哈希然后將其轉換回文件的基本名稱(即report.Rmd )時,我有點迷失了。 該錯誤最終會在調用digest::digest時發生。

有沒有人嘗試找出類似的經歷?

我認為答案取決於您在自己的外部drake_config(plan)上調用digest("report.Rmd", file = TRUE)時是否會遇到相同的錯誤。 如果它出錯(我敢打賭),那么您的文件系統可能會與R發生沖突。如果是這種情況,那么很遺憾drake無法做任何事情。

我還建議您對計划進行一些更改:

plan <- drake_plan(
  plot_step = {
    png(file_out("foo.png")),
    plot(iris$Sepal.Length ~ iris$Sepal.Width),
    dev.off()
  },
  report = render(
    input = knitr_in("report.Rmd"),
    output_file = "report.html",
    quiet = TRUE
  )  
)

或者更好的是,將您的工作划分為可重用的功能:

plot_foo = function(filename) {
  png(filename),
  plot(iris$Sepal.Length ~ iris$Sepal.Width),
  dev.off()
}

plan <- drake_plan(
  foo = plot_foo(file_out("foo.png")),
  report = render(
    input = knitr_in("report.Rmd"),
    output_file = "report.html",
    quiet = TRUE
  )  
)

目標是具有有意義的返回值和/或輸出文件的可跳過工作流程步驟。 png()dev.off()是繪制步驟的一部分,而file_out()告訴drake監視foo.png進行更改。 同樣,命名目標也是個好習慣。 通常,目標的返回值是有意義的,就像R中的變量一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM