views:

210

answers:

1

Is it possible to include .R files in the data directory of my package in the roxygen process?

I have put several .R files in the data directory. When they are sourced with data(), they read in raw data files and perform some transformations.

+2  A: 

Roxygen can be used anywhere within an R file (in other words, it doesn't have to be followed by a function). It can also be used to document any docType in the R documentation.

So you can just document your data in a separate block (something like this):

#' 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
Shane
Except you're better off using `NULL` instead of `roxygen()` so that you don't induce a run-time dependency on `roxygen`
hadley
Excellent point, thanks. Made the change.
Shane
@hadley: it might be nice to add an example like this into the roxygen vignette, and make the point about roxygen dependency? I found that to be a little confusing in terms of how to structure the files.
Shane
Thank you both Shane and Hadley for the excellent help. I see now much clearer how to use roxygen; and now R CMD check does not complain anymore. One question is left: Do I need to put the data documentation in the R subdirectory? It would be nice to teach roxygenize to look in the data directory, too...
Karsten W.
@Karsten: I tend to think that the only thing that should go in the data subdirectory is data. Roxygen provides literate programming as R code, so I like to have that all within my R files. But beyond that you might try this: roxygenize uses an environment variable "R.DIR". Set that to "data" instead and it should process R files in the data directory. @hadley: you could make a simple patch to allow for an R.DIR vector?
Shane
@Shane: I've already complained about that to the roxygen devs, and it should change in the next release
hadley