AnjaM
AnjaM

Reputation: 3029

Where are objects stored in R packages?

I am refactoring an R package of another author (previous employee of my company). The author uses multiple variables in the roxygen2 examples that apparently are stored somewhere in the package. They are accessible with pkgname:::bar. I renamed some of these variables across the entire package to improve naming consistency, let's say the variable is called foo instead of bar now, but the examples are not running any more upon devtools::check(). The error: Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'foo' not found. However, I cannot find where they are defined. There are no objects in the data folder that would be named bar and searching for the variable name within all files (in RStudio and in Windows Explorer) does not reveal anything. Yet, pkgname:::bar still works. Any ideas where I should look for bar?

Upvotes: 0

Views: 260

Answers (1)

tpetzoldt
tpetzoldt

Reputation: 5813

Variables can also be created in a normal R script of the package with foo <- new.env() and then populated with content, e.g.

foo <- new.env()

foo <- data.frame(
  x=1:10,
  y <- rnorm(10)
)

It is also possible to make the internal data hidden, e.g. .foo. As an example CRAN package marelac uses this mechanism in files aaa.R, gas_schmidt.R and some others.

Another possibility is a file sysdata.rda that can be placed in the /Rfolder, see: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-subdirectories

Upvotes: 1

Related Questions