首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >共享驱动器上的drake文件路径

共享驱动器上的drake文件路径
EN

Stack Overflow用户
提问于 2019-08-20 18:45:22
回答 1查看 149关注 0票数 0

我遇到了一些奇怪的德雷克行为,我就是搞不懂。我正试图在我的德雷克计划中添加一个.rmd。我在一台远程机器上工作,在那台机器上做一个网络驱动器。如果我试图向我的计划中添加一个.rmd文件,如下所示:

代码语言:javascript
复制
> 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时,最终会发生错误。

有谁有过这样的经验吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-22 16:03:56

我认为答案取决于在digest("report.Rmd", file = TRUE)外部调用drake_config(plan)时是否得到相同的错误。如果是错误(我打赌是这样的),那么您的文件系统可能会有一些奇怪的地方与R冲突,如果是这样的话,那么不幸的是,drake无法做任何事情。

我还建议对你的计划做一些修改:

代码语言:javascript
复制
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
  )  
)

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

代码语言:javascript
复制
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中的变量一样。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57579842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档