rpackageroxygen2

Include data examples in developing R packages


I am eager to learn how to incorporate data examples as comments written above the functions, such as:

##' @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)

I put my "data.txt" file in the directory: /pkg_Name/inst/extdata/. However, R CMD check indicates error in this step. If I proceed to R CMD build and R CMD install, then after loading the package, I cannot get the data into R session... Could anyone tell me what went wrong? Is this the correct way to include data examples at the end of the function help document?

Thanks a lot!


Solution

  • Please look at CRAN packages that include data and copy their approach. I just added data to a at-work-only package a few weeks back and it just works...

    For what it is worth, the manual has a section 1.1.5 Data in packages which explains it.