Jesse Anderson
Jesse Anderson

Reputation: 4603

Writing an R package: needing a package I don't explicitly call

I'm working on an R package that uses the spTransform function in the sp package. The rub is that this function need rgdal loaded to work, or I get an error message:

Error in eval(expr, envir, enclos) : load package rgdal for spTransform methods

My Imports statement in the DESCRIPTION file includes the following:

Imports: sp,
    rgdal

But I'm still getting the error. However, if I explcitly load rgdal (using library(rgdal)) before using the package, everything works fine. I'm guessing that when my package is loaded rgdal is not attached because none of my code uses it explcitly via :: etc.

So I think my question is: How can I make my package attach a package that I am not explicitly using?

Upvotes: 7

Views: 278

Answers (1)

F. Correhuela
F. Correhuela

Reputation: 143

As said by BondedDust, you need to import the required packages into your package NAMESPACE. To do so edit the file, adding a new line import(sp, rgdal). Further reading http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Specifying-imports-and-exports

Upvotes: 7

Related Questions