在roxygen过程中,是否可以将.R文件包含在数据目录中?
我已经将多个.R文件放入数据目录中。当它们通过data()被调用时,它们会读取原始数据文件并执行一些转换。
在roxygen过程中,是否可以将.R文件包含在数据目录中?
我已经将多个.R文件放入数据目录中。当它们通过data()被调用时,它们会读取原始数据文件并执行一些转换。
Roxygen 可以在 R 文件中的任何位置使用(换句话说,它不必后跟函数)。它还可以用于记录 R 文档中的任何 docType。
因此,您可以在单独的块中记录数据(类似于以下内容):
#' This is data to be included in my package
#'
#' @name data-name
#' @docType data
#' @author My Name \email{blahblah@@roxygen.org}
#' @references \url{data_blah.com}
#' @keywords data
NULL
从roxygen2 >4.0.0版本开始,您可以通过使用定义的对象名称(以字符串形式)来记录在其他地方定义的数据对象:
#' This is data to be included in my package
#'
#' @author My Name \email{blahblah@@roxygen.org}
#' @references \url{data_blah.com}
"data-name"
我发现研究ggplot2包中的示例非常有用。
需要注意的几件事:
R
目录下的单个.r
文件中。例如,可以查看diamonds
数据集:
#' Prices of 50,000 round cut diamonds
#'
#' A dataset containing the prices and other attributes of almost 54,000
#' diamonds. The variables are as follows:
#'
#' \itemize{
#' \item price. price in US dollars (\$326--\$18,823)
#' \item carat. weight of the diamond (0.2--5.01)
#' \item cut. quality of the cut (Fair, Good, Very Good, Premium, Ideal)
#' \item colour. diamond colour, from J (worst) to D (best)
#' \item clarity. a measurement of how clear the diamond is (I1 (worst), SI1, SI2, VS1, VS2, VVS1, VVS2, IF (best))
#' \item x. length in mm (0--10.74)
#' \item y. width in mm (0--58.9)
#' \item z. depth in mm (0--31.8)
#' \item depth. total depth percentage = z / mean(x, y) = 2 * z / (x + y) (43--79)
#' \item table. width of top of diamond relative to widest point (43--95)
#' }
#'
#' @docType data
#' @keywords datasets
#' @name diamonds
#' @usage data(diamonds)
#' @format A data frame with 53940 rows and 10 variables
NULL
这将生成一个看起来像这样的帮助文件:
NULL
而不是roxygen()
,这样你就不会在运行时依赖于roxygen
。 - hadley.R
文件放在那里来描述我的数据对象,但是R CMD Check
似乎无法解析它。 - Faustin Gashakamba