Writing R packages: how to import another package?

As a minimal working example, I'm trying to import some objects from a package MASSinto my own package (called Test) - take a dataset abbey, for example:

### In R/Test.R:
#' @import MASS
abbey     # Check that the dataset has been imported OK

### DESCRIPTION:
Package: Test
...
Imports: MASS

### NAMESPACE:
# Generated by roxygen2 (4.0.1): do not edit by hand
import(MASS)

I hit Build & Reloadin RStudio and got an error:

==> devtools::document(roclets=c('rd', 'collate', 'namespace'))

Updating Test documentation
Loading Test
Error in eval(expr, envir, enclos) : object 'abbey' not found
Writing NAMESPACE
Documentation completed

==> Rcmd.exe INSTALL --no-multiarch --with-keep.source Test

* installing to library '.../R/R-3.1.0/library'
* installing *source* package 'Test' ...
** R
** preparing package for lazy loading
Error in eval(expr, envir, enclos) : object 'abbey' not found
Error : unable to load R code in package 'Test'
ERROR: lazy loading failed for package 'Test'
* removing '.../R/R-3.1.0/library/Test'
* restoring previous '.../R/R-3.1.0/library/Test'

Exited with status 1.

It seems that even the most basic one has importfailed - the system cannot find abbey. It is clear that I must lose sight of something obvious - what is wrong?

+4
source share
1 answer

From what I tried: You cannot import an abbreviation because it is not exported using MASS.

> library(MASS)
> 'abbey' %in% getNamespaceExports(getNamespace('MASS'))
[1] FALSE

abbey - , data/abbey.rda, , .

, MASS:: abbey R/data.R:

abbey <- MASS::abbey

.

0

All Articles