Michael Henry
Michael Henry

Reputation: 631

Using sp (spatial package) from my own package results in error: could not find function

I'm developing my first package - well, actually I'm packaging some existing code - in RStudio. I've marked up all the comments with roxygen2 and this has generated a correct NAMESPACE file which includes:

import(sp)
importFrom(geosphere,distMeeus)
importFrom(geosphere,distm)

I'm using the distm() function from the geosphere package to calculate a distance matrix but it is failing:

Error in .pointsToMatrix(x) : could not find function "is.projected" 4 .pointsToMatrix(x) 3 distm(OCC, SPAD, fun = distMeeus) at peta.R#79

now is.projected() is in the sp package, which I have imported so it should be in my search path. Shouldn't it?

As an experiment I just called library(geosphere) (which also loads sp) prior to calling my package code and my function got past that point. Soooo, do I still need to call library() for every package??? That seems a bit redundant and at this point I think I'll stop and see if someone can set me straight before I break anything further...

Upvotes: 0

Views: 797

Answers (1)

Andrie
Andrie

Reputation: 179398

Edited

I don't understand why this is, but you need to add methods to your package imports:

  • Add to your DESCRIPTION:

    Imports: methods
    
  • Add to your NAMESPACE:

    import(methods)
    

Upvotes: 1

Related Questions