是否可以在 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 包中的示例很有用。

github 上的 ggplot2.r

有几点需要注意:

  • 数据集的所有 Roxygen 代码都可以包含在一个单独的文件中 .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

这会产生一个如下所示的帮助文件:

roxygen documentation example

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top