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