R Under development (unstable) (2023-05-27 r84465 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > options("rgdal_show_exportToProj4_warnings"="none") > library(sp) The legacy packages maptools, rgdal, and rgeos, underpinning this package will retire shortly. Please refer to R-spatial evolution reports on https://r-spatial.org/r/2023/05/15/evolution4.html for details. This package is now running under evolution status 0 > data(meuse) > x = meuse > > coordinates(x) <- c("x", "y") > try(proj4string(x) <- 1.5) Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'proj4string<-' for signature '"SpatialPointsDataFrame", "numeric"' > try(coordinates(a) <- cbind(1:10, 10:1)) Error : object 'a' not found > # fails because a is not found; passes if a assigned NULL, see pass1.R > > x = meuse > # invalid coordinate formulae: > try(coordinates(x) <- ~log(x)+sqrt(y)) # no expressions allowed Error in `[.data.frame`(object, , -coord.numbers, drop = FALSE) : undefined columns selected > try(coordinates(x) <- ~x+y+z) # z is not present Error in eval(predvars, data, env) : object 'z' not found > x$x2 = x$x^2 > x$y2 = x$y^2 > try(coordinates(x) <- ~x+y+x2+y2) # 4D now passes check... > x = meuse > try(coordinates(x) <- ~x) # 1D not allowed Error in validObject(.Object) : invalid class "SpatialPoints" object: spatial.dimension should be 2 or more > > # is.na.sp.coords > a = data.frame(cbind(xx=c(1,NA,2,10),yy=c(2,NA,NA,20))) > try(coordinates(a) <- c("xx", "yy")) # should fail! Error in `coordinates<-`(`*tmp*`, value = c("xx", "yy")) : coordinates are not allowed to contain missing values > > x = meuse[1:4,] > coordinates(x) = c(1,2) > # this should fail -- zinc is not a row: > #(and will break automatic testing, so outcommented!) > #try(q <- x["zinc",]) > # this will issue warning under S-Plus, or a silent rename under R > try(x[c("zinc", "copper", "zinc")]) coordinates zinc copper zinc.1 1 (181072, 333611) 1022 85 1022 2 (181025, 333558) 1141 81 1141 3 (181165, 333537) 640 68 640 4 (181298, 333484) 257 81 257 > > # this will fail, as "x" is not in the data part: > try(x[c("zinc", "x", "copper", "zinc")]) Error in `[.data.frame`(x@data, i, j, ..., drop = FALSE) : undefined columns selected > > # row index containing missing values will fail: > try(xx <- x[c(1:3,NA),]) Error in x[c(1:3, NA), ] : NAs not permitted in row index > > xx = data.frame(x=1:10, y=1:10) > > # fails; use SpatialPoints() to create points without attribute > try(coordinates(xx) <- c("x", "y")) > > x = matrix(3, 5, 2) > dimnames(x) = list(c(1,1:4), NULL) > y = data.frame(a = 1:5, b = 5:1) > try(SpatialPointsDataFrame(x, y)) # will complain: Error in SpatialPointsDataFrame(x, y) : row.names of data and dimnames of coords do not match In addition: Warning message: In SpatialPointsDataFrame(x, y) : forming a SpatialPointsDataFrame based on maching IDs, not on record order. Use match.ID = FALSE to match on record order > SpatialPointsDataFrame(x, y, match.ID = FALSE) # won't complain coordinates a b 1 (3, 3) 1 5 2 (3, 3) 2 4 3 (3, 3) 3 3 4 (3, 3) 4 2 5 (3, 3) 5 1 Warning messages: 1: In validityMethod(object) : duplicate rownames are interpreted by rgeos as MultiPoints; use SpatialMultiPoints to define these; in future sp versions this warning will become an error 2: In validityMethod(as(object, superClass)) : duplicate rownames are interpreted by rgeos as MultiPoints; use SpatialMultiPoints to define these; in future sp versions this warning will become an error > > Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) > Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2))) > Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5))) > Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE) > > Srs1 = Polygons(list(Sr1), "s1") > Srs2 = Polygons(list(Sr2), "s2") > Srs3 = Polygons(list(Sr3, Sr4), "s2") > try(SR <- SpatialPolygons(list(Srs1,Srs2,Srs3))) # will complain Error in validObject(res) : invalid class "SpatialPolygons" object: non-unique Polygons ID slot values > Srs3 = Polygons(list(Sr3, Sr4), "s3/4") > SR = SpatialPolygons(list(Srs1,Srs2,Srs3)) # won't complain > try(SRx <- SR[c(1,2,NA),]) Error in SR[c(1, 2, NA), ] : NAs not permitted in row index > > attr = data.frame(a=1:3, b=3:1, row.names=c("s1", "s2", "s3")) > try(SrDf <- SpatialPolygonsDataFrame(SR, attr)) # will complain Error in SpatialPolygonsDataFrame(SR, attr) : row.names of data and Polygons IDs do not match > SrDf = SpatialPolygonsDataFrame(SR, attr, match.ID = FALSE) # won't complain > attr = data.frame(a=1:3, b=3:1, row.names=c("s1", "s2", "s3/4")) > SrDf = SpatialPolygonsDataFrame(SR, attr) # won't complain > > l1 = cbind(c(1,2,3),c(3,2,2)) > l1a = cbind(l1[,1]+.05,l1[,2]+.05) > l2 = cbind(c(1,2,3),c(1,1.5,1)) > Sl1 = Line(l1) > Sl1a = Line(l1a) > Sl2 = Line(l2) > S1 = Lines(list(Sl1, Sl1a), ID="a") > S2 = Lines(list(Sl2), ID="b") > S3 = Lines(list(Sl2), ID="a") > Sl = SpatialLines(list(S1,S2)) # won't complain > try(Sl1 <- SpatialLines(list(S1,S3))) # will complain Error in validObject(.Object) : invalid class "SpatialLines" object: non-unique Lines ID slot values > try(Sl1 <- Sl[c(NA,2),]) # will fail Error in Sl[c(NA, 2), ] : NAs not permitted in row index > > df = data.frame(z = c(1,2), row.names=sapply(slot(Sl, "lines"), function(x) slot(x, "ID"))) > Sldf = SpatialLinesDataFrame(Sl, data = df) # won't complain > df1 = data.frame(z = c(1,2)) > try(Sldf1 <- SpatialLinesDataFrame(Sl, data = df1)) # will complain Error in SpatialLinesDataFrame(Sl, data = df1) : row.names of data and Lines IDs do not match > Sldf1 = SpatialLinesDataFrame(Sl, data = df1, match.ID = FALSE) # won't complain > try(Sldf1 <- Sldf1[c(1,NA),]) Error in Sldf1[c(1, NA), ] : NAs not permitted in row index > > data(meuse.grid) > gridded(meuse.grid) = ~x+y > try(x <- meuse.grid[c(1:10,NA,12),]) Error in meuse.grid[c(1:10, NA, 12), ] : NAs not permitted in row index > fullgrid(meuse.grid) = TRUE > try(x <- meuse.grid[c(1:10,NA,12),]) Error in meuse.grid[c(1:10, NA, 12), ] : NAs not permitted in index > > try(x <- meuse[[c("zinc", "cadmium")]]) Error in .subset2(x, i, exact = exact) : subscript out of bounds > try(meuse[[c("zn", "cd")]] <- cbind(meuse$zinc, meuse$cadmium)) Error in `[[<-`(`*tmp*`, i, value = value) : no such index at level 1 > > data(meuse.grid) > coordinates(meuse.grid) <- c("x", "y") > gridded(meuse.grid) <- TRUE > gridparameters(meuse.grid) cellcentre.offset cellsize cells.dim x 178460 40 78 y 329620 40 104 > > image(meuse.grid) > image(meuse.grid[2]) > image(meuse.grid, 2) > try(image(meuse.grid, 0)) Error in .subset2(x, i, exact = exact) : subscript out of bounds > image(meuse.grid[3], breaks=c(0,.2,.5,.8,1), col = bpy.colors(4)) > image(meuse.grid, 3, zlim = c(0,.3)) > image(meuse.grid, 3, zlim = c(.3,.1)) > image(meuse.grid, 3, zlim = c(.2,.8)) > image(meuse.grid, 3, zlim = c(.2,.8), breaks = c(.2,.4,.6,.8), + col = bpy.colors(3)) > > data(meuse.grid) > set.seed(1) > meuse.grid$x <- meuse.grid$x + rnorm(length(meuse.grid$x), 0, 0.0002) > meuse.grid$y <- meuse.grid$y + rnorm(length(meuse.grid$y), 0, 0.0002) > coordinates(meuse.grid) <- c("x", "y") > try(gridded(meuse.grid) <- TRUE) suggested tolerance minimum: 0.964318 Error in points2grid(points, tolerance, round) : dimension 1 : coordinate intervals are not constant > try(meuse.grid <- SpatialPixelsDataFrame(as(meuse.grid, "SpatialPoints"), + data=as(meuse.grid, "data.frame"), tolerance=0.077)) > gridparameters(meuse.grid) cellcentre.offset cellsize cells.dim x 178460 39.99912 78 y 329620 39.99920 104 > > data(meuse.grid_ll) > try(gridded(meuse.grid_ll) <- TRUE) suggested tolerance minimum: 0.818323 Error in points2grid(points, tolerance, round) : dimension 1 : coordinate intervals are not constant > try(meuse.grid_ll <- SpatialPixelsDataFrame(as(meuse.grid_ll, "SpatialPoints"), data=as(meuse.grid_ll, "data.frame"), tolerance=0.9)) > gridparameters(meuse.grid_ll) cellcentre.offset cellsize cells.dim x 5.721109 0.0005312853 84 y 50.955770 0.0003318105 112 > > try(CRS("+proj=latlon +ellps=WGS84")) Error in CRS("+proj=latlon +ellps=WGS84") : northings must follow eastings: +proj=latlon +ellps=WGS84 > try(CRS("+proj=lonlat +ellps=WGS84")) Coordinate Reference System: Deprecated Proj.4 representation: +proj=longlat +ellps=WGS84 +no_defs WKT2 2019 representation: GEOGCRS["unknown", DATUM["Unknown based on WGS84 ellipsoid", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1], ID["EPSG",7030]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8901]], CS[ellipsoidal,2], AXIS["longitude",east, ORDER[1], ANGLEUNIT["degree",0.0174532925199433, ID["EPSG",9122]]], AXIS["latitude",north, ORDER[2], ANGLEUNIT["degree",0.0174532925199433, ID["EPSG",9122]]]] Warning message: In CRS("+proj=lonlat +ellps=WGS84") : 'lonlat' changed to 'longlat': +proj=longlat +ellps=WGS84 > > proc.time() user system elapsed 0.64 0.07 0.71