0

I am trying to load a shapefile using the the rgdal package. Why is it that this command fails:

plot(rgdal::readOGR(dsn=system.file("vectors/Up.tab", package = "rgdal")[1],layer="Up"))

With error:

Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'

while this one suceeds

library(rgdal)
plot(readOGR(dsn=system.file("vectors/Up.tab", package = "rgdal")[1],layer="Up"))

My guess is that is has something to do with a hidden plot method for SpatialGDAL. How would I uncover what is going on behind the scenes with plot ?

I am trying to call readOGR after "importing" rgdal within a package I am writing. In an effort to avoid namespace conflicts I am using importFrom rgdal readOGR.

jsta
  • 3,216
  • 25
  • 35
  • "this command fails". Error message? –  Jun 18 '15 at 23:14
  • I guess it is because as long as you don't load the `rgda` package, `[` is not defined for `SpatialGDAL` class. –  Jun 18 '15 at 23:26
  • I don't think that's it. The example above is meant to be reproducible. My actual use-case fails with the same error and `[` is not used. My guess is that is has something to do with a hidden `plot` method for `SpatialGDAL`. How would I uncover what is going on behind the scenes with `plot' ? – jsta Jun 18 '15 at 23:30
  • Why do you ask if you know it is related to `plot`? Just load the library. –  Jun 18 '15 at 23:31
  • If you are going to use a plot method on whatever class the object delivered by readOGR is, then you need to import the plot-method as well. Looks like its an S4 method. – IRTFM Jun 18 '15 at 23:47

0 Answers0