user1420372
user1420372

Reputation: 2187

Include example using data in documentation of that data (when developing R package)

In documentation of data within an R package (using Roxygen via Rstudio), is it possible to include an example that uses that data?

E.g. TestPackage.R in the R directory

#' My New Colour
#' 
#' Enables use of my new colour \emph{aNewColour} in plots.
#' @name aNewColour
#' @docType data
#' @format A colour defined by rgb(red=232,green=81,blue=0,maxColorValue=255)
#' @usage data(allNewColours)
#' @examples
#' curve(dnorm,from=-4,to=4,col=aNewColour,lwd=2)
NULL

In the same R directory, I have a file: allNewColours.rda, which consists only of the variable aNewColour with value #E85100.

When I press Check on the Build menu of R studio (equivalent to the command R CMD Check I believe), I get the following error message:

** Examples

curve(dnorm,from=-4,to=4,col=aNewColour,lwd=2) Error in plot.xy(xy, type, ...) : object 'aNewColour' not found Calls: curve -> plot -> plot.default -> plot.xy Execution halted Error: Command failed (1) Execution halted

Exited with status 1.

Is it possible to use the data "aNewColour" in the example of the documentation of "aNewColour" ?

Edit: Okay I found my problem - If I move the .rda file to a data folder (at the same level as the R folder, all works)... Had been struggling with this for ages only to determine the solution within seconds of posting this question ...

Upvotes: 0

Views: 371

Answers (1)

user1420372
user1420372

Reputation: 2187

move the .rda file to a data folder - and enter LazyData: yes in the DESCRIPTION file

Upvotes: 1

Related Questions