我遇到了一些奇怪的德雷克行为,我就是搞不懂。我正试图在我的德雷克计划中添加一个.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时,最终会发生错误。
有谁有过这样的经验吗?
发布于 2019-08-22 16:03:56
我认为答案取决于在digest("report.Rmd", file = TRUE)外部调用drake_config(plan)时是否得到相同的错误。如果是错误(我打赌是这样的),那么您的文件系统可能会有一些奇怪的地方与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中的变量一样。
https://stackoverflow.com/questions/57579842
复制相似问题