我在R中有这个奇怪的场景,其中rmarkdown :: render()函数意外执行。给出以下简单的脚本/ test.Rmd
---
title: test
---
```{r test}
plot(1:10)
```
然后我有以下R代码:
> getwd()
[1] "/projects/test_project"
library('rmarkdown')
rmarkdown::render("scripts/test.Rmd", output_file = 'test.html', output_dir = paste( getwd(), '/', 'reports', sep = '') )
这最终会产生输出:
/projects/test_project/scripts/reports/test.html
这对我来说意外,因为:
> paste( getwd(), '/', 'reports', sep = '') )
/projects/test_project/reports
我希望在这里生成test.html /projects/test_project/reports/test.html。有趣的是,当我放弃getwd()并将路径用作字符串时:
> render("scripts/test.Rmd", output_file = 'test.html', output_dir = "/projects/test_project/reports" )
这将在预期位置生成文件。有什么想法吗?
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin14.1.0 (64-bit)
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] splines grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] rmarkdown_0.4.2 scales_0.2.4 broom_0.3.5 data.table_1.9.4 gplots_2.15.0 RColorBrewer_1.1-2 reshape2_1.4.1 dplyr_0.3.0.2 ggplot2_1.0.0
[10] stringr_0.6.2 plyr_1.8.1 survival_2.37-7 xtable_1.7-4 fields_7.1 maps_2.3-9 spam_1.0-1 knitr_1.8 argparse_1.0.1
[19] proto_0.3-10 vimcom_1.0-0 setwidth_1.0-3 colorout_1.1-0
loaded via a namespace (and not attached):
[1] assertthat_0.1 bitops_1.0-6 caTools_1.17.1 chron_2.3-45 colorspace_1.2-4 DBI_0.3.1 digest_0.6.8 evaluate_0.5.5 findpython_1.0.1
[10] formatR_1.0 gdata_2.13.3 getopt_1.20.0 gtable_0.1.2 gtools_3.4.1 htmltools_0.2.6 KernSmooth_2.23-13 lazyeval_0.1.10 magrittr_1.5
[19] MASS_7.3-35 munsell_0.4.2 parallel_3.1.2 psych_1.4.8.11 Rcpp_0.11.3 rjson_0.2.15 tidyr_0.2.0 tools_3.1.2 yaml_2.1.13
答案 0 :(得分:1)
我遇到了同样的问题,感觉可能是因为render()
函数中存在一个小错误。我在其github页面上提出了一个问题:
https://github.com/rstudio/rmarkdown/issues/416
作为我正在使用的解决方法/黑客:
require(rmarkdown)
fl = render("awesome.Rmd")
file.copy(fl, getwd())
希望有所帮助。