你考虑过使用knitr::spin
吗?共有三种类型的注释用于定义最终文件的呈现方式。
#
标准的 R 评论
#'
在行首将呈现为降价
#+
块选项
通过编写 data-assembly.R 脚本,然后调用knitr::spin("data-assembly.R")
.html 文件,将生成可能提供所需详细信息的文件。
示例 data-assembly.R 文件:
#' # Data Assembly Process
#' This document provides details on the construction of the final analysis data
#' set.
#'
#' The namespaces needed for this work are:
#+ message = FALSE
library(tidyverse)
#' Our first step is to read in the data sets. For this example, we'll just use
#' the `mtcars` data set
mtcars
#' A summary of the `mtcars` data set is below
summary(mtcars)
#' Let's only use data records for cars with automatic transmissions
mt_am_cars <- dplyr::filter(mtcars, am == 1)
mt_am_cars