使用rmarkdown :: render设置文档标题(标题,作者,日期) [英] Using rmarkdown::render to set document header (title, author, date)

查看:496
本文介绍了使用rmarkdown :: render设置文档标题(标题,作者,日期)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rmarkdown::render("script.r")创建R脚本的HTML版本.输出的开头是 script.r 作为标题,我的登录名是作者,而当前的date作为日期.我不想放弃我的登录名,也不想放弃我的工作时间表..

我知道可以在Rmd文件内的YAML块中设置此元数据(标题,作者,日期),但我想避免创建/编辑此文件,并且仅使用原始R脚本. /p>

是否可以通过rmarkdown::render或其他功能(如knitr::opts_chunk$set)设置(标题,作者,日期)元数据?

或者,可以在R脚本中设置此元数据吗?

请避免建议我改写一个Rmd文件.

解决方案

Rmarkdown文档(请参见?compile_notebook)描述了一种方法,该方法包括在您的script.R文件中包含特殊格式的注释.

例如,在脚本中包含此注释以设置标题,作者和日期.

#' ---
#' title: "Crop Analysis Q3 2013"
#' author: "John Smith"
#' date: "May 3rd, 2014"
#' ---

这将为您提供以下输出:

I am using rmarkdown::render("script.r") to create an HTML version of an R script. The output starts with script.r as title, my login as author, and the current date as date. I don't want to give away my login, nor my work schedule..

I know this metadata (title, author, date) can be set in a YAML block inside a Rmd file, but I would like to avoid creating/editing this file, and work only with the original R script.

Is there a way to set (title, author, date) metadata via rmarkdown::render, or other functions like knitr::opts_chunk$set?

Alternatively, can this metadata be set inside the R script?

Please avoid suggesting that I should write an Rmd file instead..

解决方案

The Rmarkdown documentation (see ?compile_notebook) describes one way to do this by including a specially formatted comment in your script.R file.

For example, include this comment in your script to set the title, author and date.

#' ---
#' title: "Crop Analysis Q3 2013"
#' author: "John Smith"
#' date: "May 3rd, 2014"
#' ---

This will give you the following output:

这篇关于使用rmarkdown :: render设置文档标题(标题,作者,日期)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆