如何使用roxygen记录数据集?

时间:2010-02-22 11:03:59

标签: r documentation-generation r-package roxygen

是否可以在roxygen过程中将.R文件包含在我的包的数据目录中?

我在数据目录中放了几个.R文件。当他们使用data()时,他们会读取原始数据文件并执行一些转换。

3 个答案:

答案 0 :(得分:42)

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

答案 1 :(得分:30)

从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"

答案 2 :(得分:20)

我发现研究ggplot2包中的例子非常有用。

请参阅ggplot2.r on github

注意事项:

  • 数据集的所有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