Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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?

like image 621
Jesse Anderson Avatar asked Apr 30 '15 21:04

Jesse Anderson


1 Answers

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

like image 159
F. Correhuela Avatar answered Dec 28 '22 22:12

F. Correhuela