我正在使用
drake
要创建多个输出文件,我要在其中通过变量指定路径。有点像
outpath <- "data"
outfile <- file.path(outpath, "mydata.csv")
write.csv(df, outfile)
但是
file_out
除了文字字符之外,似乎无法处理给它的参数。
给出一个小的代码示例:
代码设置
library(drake)
outpath <- "data"
# for reproducibility only
if (!dir.exists(outpath)) dir.create(outpath)
make_data <- function() data.frame(x = 1:10, y = rnorm(10))
工作代码
直接指定文件:
p0 <- drake_plan(
df = make_data(),
write.csv(df, file_out("data/mydata0.csv"))
)
make(p0)
#> target file "data/mydata0.csv"
失效代码
使用
file.path
建造出口
p1 <- drake_plan(
df = make_data(),
write.csv(df, file_out(file.path(outpath, "mydata1.csv")))
)
make(p1)
#> target file "mydata1.csv"
#> Error: The file does not exist: mydata1.csv
#> In addition: Warning message:
#> File "mydata1.csv" was built or processed,
#> but the file itself does not exist.
我想德雷克只找到文本字符串作为目标,而不是
file.path(...)
例如,这也失败了
p2 <- drake_plan(
df = make_data(),
outfile = file.path(outpath, "mydata1.csv"),
write.csv(df, file_out(outfile))
)
#> Error: found an empty file_out() in command: write.csv(df, file_out(outfile))
知道怎么解决吗?