ali*_*boy 23 r package roxygen2
我渴望学习如何将数据示例合并为函数上方的注释,例如:
##' @examples
##' ## Set working directory...
##' ## Load data into R session:
##' data <- system.file("extdata", "data.txt", package="...", sep="\t", header=TRUE, stringsAsFactors = FALSE)
##'
##' ## For reproducible results:
##' set.seed(999)
Run Code Online (Sandbox Code Playgroud)
我将"data.txt"文件放在目录中:/ pkg_Name/inst/extdata /.但是,R CMD检查表示此步骤中的错误.如果我继续进行R CMD构建和R CMD安装,那么在加载软件包后,我无法将数据导入R会话......有人能告诉我出了什么问题吗?这是在函数帮助文档末尾包含数据示例的正确方法吗?
非常感谢!
Jer*_*lim 32
Hadley Wickham在他的书"R Packages"中有一章介绍如何将数据合并到R包中.
Dirk指向包中数据的官方文档.
或者,这是一个从ggplot2包中学习如何使用rda文件和roxygen合并数据的方法的示例.
这是data
ggplot2包中的目录.在该示例中,每个数据文件存储在单独的rda
文件中(例如,使用生成的文件生成)save(foo, file='foo.rda')
.
请参阅文件data.r以获取Roxygen命令以生成数据的Rmd帮助文件:例如,
#' 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:
#'
#' @format A data frame with 53940 rows and 10 variables:
#' \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 color: 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)
#' }
"diamonds"
Run Code Online (Sandbox Code Playgroud)