2

I have been running the following code in RStudio for testing vectorplot functionality in R:

library(raster)
library(rasterVis)
library(lattice)

proj <- CRS('+proj=longlat +datum=WGS84')

df <- expand.grid(x=seq(-2, 2, .01), y=seq(-2, 2, .01))
df$z <- with(df, (3*x^2 + y)*exp(-x^2-y^2))
r1 <- rasterFromXYZ(df, crs=proj)
df$z <- with(df, x*exp(-x^2-y^2))
r2 <- rasterFromXYZ(df, crs=proj)
df$z <- with(df, y*exp(-x^2-y^2))
r3 <- rasterFromXYZ(df, crs=proj)
s <- stack(r1, r2, r3)
names(s) <- c('R1', 'R2', 'R3')

vectorplot(r1)

The above code is giving me the following error:

Error in subset.default(sa, 1) : 'subset' must be logical

The code was running well for some previous versions of the packages (raster, rastervis) on Mac OS. Would you please suggest how to resolve the error and make vectorplot functional again?

Currently, I am using windows 10 and the following versions of R and RStudio:

  • R: 4.1.2 (2021-11-01)
  • RStudio: 2021.09.1+372 "Ghost Orchid" Release (2021-11-08) for Windows
Phil
  • 7,287
  • 3
  • 36
  • 66
  • 1
    The docs for `vectorplot` say it works on `Raster` and `RasterStack` objects, but `class(r1)` gives `"RasterLayer"`. Looks like they weren't expecting an object of that type. – user2554330 Nov 20 '21 at 10:36
  • Actually, your code is very similar (identical?) to the code in the Examples for `?vectorplot`, but the package authors have marked that code as "Not run". You should report this to the package maintainer as a bug. – user2554330 Nov 20 '21 at 10:42
  • 2
    Actually, this bug has been fixed in the development version of the package, which you can install using `remotes::install_packages("oscarperpinan/rasterVis")`. – user2554330 Nov 20 '21 at 10:50

0 Answers0