这是 rmarkdown::render() 的包装,强制执行 "reprex" 心态。这是所发生情况的简化版本:
callr::r(
  function(input) {
    rmarkdown::render(input, envir = globalenv(), encoding = "UTF-8")
  },
  args = list(input = input),
  spinner = is_interactive(),
  stdout = std_file, stderr = std_file
)
需要注意的主要特点
- 
rmarkdown::render()使用callr::r()在新的 R 会话中执行。目标是消除对象、附加包和会话状态的其他方面从当前会话泄漏到渲染会话中。此外,系统和 user-level.Rprofile也会被忽略。 - 
代码在这个新 R 会话的
globalenv()中进行评估,这意味着方法分派按照大多数人期望的方式工作。 - 
输入文件假定为 UTF-8,这是 v1.24 起的 knit 要求。
 - 
如果 YAML frontmatter 包含
std_err_out: TRUE,则渲染 R 会话的标准输出和错误将在std_file中捕获,然后注入到渲染结果中。 
reprex_render() 设计用于使用 reprex_document() 输出格式,通常通过调用 reprex() 。 reprex_render() 可以与其他 R Markdown 输出格式一起使用,但它不是 well-tested。
参数
- input
 - 
要渲染的输入文件。这可以是
.R脚本或.RmdR Markdown 文档。 - html_preview
 - 
逻辑性强。是否在查看器(RStudio 或浏览器)中显示渲染输出。在非交互式会话中始终
FALSE。阅读有关opt()的更多信息。 - encoding
 - 
输入文件的编码。请注意,唯一可接受的值是 "UTF-8",从 v1.24 开始,knitr 要求使用该值。这纯粹是为了技术方便而作为参数公开,与 RStudio IDE 中的 "Knit" 按钮相关。
 
值
传递rmarkdown::render()的输出,即输出文件的路径。
相关用法
- R reprex reprex_locale 在特定区域设置中渲染 reprex
 - R reprex reprex_document 代表输出格式
 - R reprex reprex 渲染一个reprex
 - R reprex un-reprex 取消渲染reprex
 - R SparkR repartition用法及代码示例
 - R SparkR repartitionByRange用法及代码示例
 - R SparkR read.stream用法及代码示例
 - R readr datasource 创建源对象。
 - R readr melt_delim 返回分隔文件中每个标记的熔化数据(包括 csv 和 tsv)
 - R readr read_rds 读/写 RDS 文件。
 - R readr read_lines 从文件中读取/写入行
 - R readr parse_number 灵活地解析数字
 - R SparkR refreshByPath用法及代码示例
 - R readr read_fwf 将固定宽度文件读入 tibble
 - R readxl read_excel 读取 xls 和 xlsx 文件
 - R SparkR refreshTable用法及代码示例
 - R readr read_builtin 从包中读取内置对象
 - R readr Tokenizers 分词器。
 - R readr melt_table 返回空格分隔文件中每个标记的熔化数据
 - R readr date_names 创建或检索日期名称
 - R SparkR read.jdbc用法及代码示例
 - R readr type_convert 重新转换现有 DataFrame 中的字符列
 - R readxl excel_sheets 列出 Excel 电子表格中的所有工作表
 - R readxl readxl_example 获取 readxl 示例的路径
 - R readxl excel_format 确定文件格式
 
注:本文由纯净天空筛选整理自Jennifer Bryan等大神的英文原创作品 Render a document in a new R session。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
