更改knitr chunk默认外部文档

时间:2016-09-19 23:15:59

标签: r knitr r-markdown pandoc chunks

我教一个实验室,让我的学生在.Rmd文件中写下答案。为了评分,我下载并批量渲染它们为pdf。我使用以下脚本来渲染所有内容并保存在文件中。

[Editor(typeof(BrowseForFolderEditor), typeof(DialogPropertyValueEditor))]
public string TargetPath { get; set; }

这最后一项任务我忘了在块中设置library(rmarkdown) # Handy functions for concatenating strings because I want to do it like a Python # programmer damnit! `%s%` <- function(x,y) {paste(x,y)} `%s0%` <- function(x,y) {paste0(x,y)} # You should set the working directory to the one where the assignments are # located. Also, make sure ONLY .rmd files are there; anything else may cause # a problem. subs <- list.files(getwd()) # Get list of files in working directory errorfiles <- c() # A vector for names of files that produced errors for (f in subs) { print(f) tryCatch({ # Try to turn the document into a PDF file and save in a pdfs subdirectory # (you don't need to make the subdirectory; it will be created automatically # if it does not exist). render(f, pdf_document(), output_dir = getwd() %s0% "/pdfs") }, # If an error happens, complain, then save the name in errorfiles error = function(c) { warning("File" %s% "did not render!") warning(c) errorfiles <- c(errorfiles, f) }) } ,因此如果发现错误,文档将无法编译,我将不得不去捕获这些错误并修复它们。我尝试修改此代码,以便将参数error=TRUE设置为默认在文档外。不幸的是,我已经在这工作了好几个小时,却没有办法这样做。

如何更改此代码,以便我可以在外部更改此参数? (请记住,我不拥有计算机,因此无法安装任何设备,但安装了 knitr rmarkdown 软件包。)

0 个答案:

没有答案