Debian Codegraph @

tests/fail1.Rout.save

raw
1
2 R version 4.4.0 (2024-04-24) -- "Puppy Cup"
3 Copyright (C) 2024 The R Foundation for Statistical Computing
4 Platform: x86_64-pc-linux-gnu
5
6 R is free software and comes with ABSOLUTELY NO WARRANTY.
7 You are welcome to redistribute it under certain conditions.
8 Type 'license()' or 'licence()' for distribution details.
9
10 R is a collaborative project with many contributors.
11 Type 'contributors()' for more information and
12 'citation()' on how to cite R or R packages in publications.
13
14 Type 'demo()' for some demos, 'help()' for on-line help, or
15 'help.start()' for an HTML browser interface to help.
16 Type 'q()' to quit R.
17
18 > options("rgdal_show_exportToProj4_warnings"="none")
19 > library(sp)
20 > data(meuse)
21 > x = meuse
22 >
23 > coordinates(x) <- c("x", "y")
24 > inherits(try(proj4string(x) <- 1.5, silent = TRUE), "try-error")
25 [1] TRUE
26 > try(coordinates(a) <- cbind(1:10, 10:1))
27 Error : object 'a' not found
28 > # fails because a is not found; passes if a assigned NULL, see pass1.R
29 >
30 > x = meuse
31 > # invalid coordinate formulae:
32 > try(coordinates(x) <- ~log(x)+sqrt(y)) # no expressions allowed
33 Error in `[.data.frame`(object, , -coord.numbers, drop = FALSE) :
34 undefined columns selected
35 > try(coordinates(x) <- ~x+y+z) # z is not present
36 Error in eval(predvars, data, env) : object 'z' not found
37 > x$x2 = x$x^2
38 > x$y2 = x$y^2
39 > try(coordinates(x) <- ~x+y+x2+y2) # 4D now passes check...
40 > x = meuse
41 > try(coordinates(x) <- ~x) # 1D not allowed
42 Error in validObject(.Object) :
43 invalid class "SpatialPoints" object: spatial.dimension should be 2 or more
44 >
45 > # is.na.sp.coords
46 > a = data.frame(cbind(xx=c(1,NA,2,10),yy=c(2,NA,NA,20)))
47 > try(coordinates(a) <- c("xx", "yy")) # should fail!
48 Error in `coordinates<-`(`*tmp*`, value = c("xx", "yy")) :
49 coordinates are not allowed to contain missing values
50 >
51 > x = meuse[1:4,]
52 > coordinates(x) = c(1,2)
53 > # this should fail -- zinc is not a row:
54 > #(and will break automatic testing, so outcommented!)
55 > #try(q <- x["zinc",])
56 > # this will issue warning under S-Plus, or a silent rename under R
57 > try(x[c("zinc", "copper", "zinc")])
58 coordinates zinc copper zinc.1
59 1 (181072, 333611) 1022 85 1022
60 2 (181025, 333558) 1141 81 1141
61 3 (181165, 333537) 640 68 640
62 4 (181298, 333484) 257 81 257
63 >
64 > # this will fail, as "x" is not in the data part:
65 > try(x[c("zinc", "x", "copper", "zinc")])
66 Error in `[.data.frame`(x@data, i, j, ..., drop = FALSE) :
67 undefined columns selected
68 >
69 > # row index containing missing values will fail:
70 > try(xx <- x[c(1:3,NA),])
71 Error in x[c(1:3, NA), ] : NAs not permitted in row index
72 >
73 > xx = data.frame(x=1:10, y=1:10)
74 >
75 > # fails; use SpatialPoints() to create points without attribute
76 > try(coordinates(xx) <- c("x", "y"))
77 >
78 > x = matrix(3, 5, 2)
79 > dimnames(x) = list(c(1,1:4), NULL)
80 > y = data.frame(a = 1:5, b = 5:1)
81 > try(SpatialPointsDataFrame(x, y)) # will complain:
82 Error in SpatialPointsDataFrame(x, y) :
83 row.names of data and dimnames of coords do not match
84 In addition: Warning message:
85 In SpatialPointsDataFrame(x, y) :
86 forming a SpatialPointsDataFrame based on maching IDs, not on record order. Use match.ID = FALSE to match on record order
87 > SpatialPointsDataFrame(x, y, match.ID = FALSE) # won't complain
88 coordinates a b
89 1 (3, 3) 1 5
90 2 (3, 3) 2 4
91 3 (3, 3) 3 3
92 4 (3, 3) 4 2
93 5 (3, 3) 5 1
94 Warning messages:
95 1: In validityMethod(object) :
96 duplicate rownames are interpreted by rgeos as MultiPoints; use SpatialMultiPoints to define these; in future sp versions this warning will become an error
97 2: In validityMethod(as(object, superClass)) :
98 duplicate rownames are interpreted by rgeos as MultiPoints; use SpatialMultiPoints to define these; in future sp versions this warning will become an error
99 >
100 > Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
101 > Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)))
102 > Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5)))
103 > Sr4 = Polygon(cbind(c(5,6,6,5,5),c(4,4,3,3,4)), hole = TRUE)
104 >
105 > Srs1 = Polygons(list(Sr1), "s1")
106 > Srs2 = Polygons(list(Sr2), "s2")
107 > Srs3 = Polygons(list(Sr3, Sr4), "s2")
108 > try(SR <- SpatialPolygons(list(Srs1,Srs2,Srs3))) # will complain
109 Error in validObject(res) :
110 invalid class "SpatialPolygons" object: non-unique Polygons ID slot values
111 > Srs3 = Polygons(list(Sr3, Sr4), "s3/4")
112 > SR = SpatialPolygons(list(Srs1,Srs2,Srs3)) # won't complain
113 > try(SRx <- SR[c(1,2,NA),])
114 Error in SR[c(1, 2, NA), ] : NAs not permitted in row index
115 >
116 > attr = data.frame(a=1:3, b=3:1, row.names=c("s1", "s2", "s3"))
117 > try(SrDf <- SpatialPolygonsDataFrame(SR, attr)) # will complain
118 Error in SpatialPolygonsDataFrame(SR, attr) :
119 row.names of data and Polygons IDs do not match
120 > SrDf = SpatialPolygonsDataFrame(SR, attr, match.ID = FALSE) # won't complain
121 > attr = data.frame(a=1:3, b=3:1, row.names=c("s1", "s2", "s3/4"))
122 > SrDf = SpatialPolygonsDataFrame(SR, attr) # won't complain
123 >
124 > l1 = cbind(c(1,2,3),c(3,2,2))
125 > l1a = cbind(l1[,1]+.05,l1[,2]+.05)
126 > l2 = cbind(c(1,2,3),c(1,1.5,1))
127 > Sl1 = Line(l1)
128 > Sl1a = Line(l1a)
129 > Sl2 = Line(l2)
130 > S1 = Lines(list(Sl1, Sl1a), ID="a")
131 > S2 = Lines(list(Sl2), ID="b")
132 > S3 = Lines(list(Sl2), ID="a")
133 > Sl = SpatialLines(list(S1,S2)) # won't complain
134 > try(Sl1 <- SpatialLines(list(S1,S3))) # will complain
135 Error in validObject(.Object) :
136 invalid class "SpatialLines" object: non-unique Lines ID slot values
137 > try(Sl1 <- Sl[c(NA,2),]) # will fail
138 Error in Sl[c(NA, 2), ] : NAs not permitted in row index
139 >
140 > df = data.frame(z = c(1,2), row.names=sapply(slot(Sl, "lines"), function(x) slot(x, "ID")))
141 > Sldf = SpatialLinesDataFrame(Sl, data = df) # won't complain
142 > df1 = data.frame(z = c(1,2))
143 > try(Sldf1 <- SpatialLinesDataFrame(Sl, data = df1)) # will complain
144 Error in SpatialLinesDataFrame(Sl, data = df1) :
145 row.names of data and Lines IDs do not match
146 > Sldf1 = SpatialLinesDataFrame(Sl, data = df1, match.ID = FALSE) # won't complain
147 > try(Sldf1 <- Sldf1[c(1,NA),])
148 Error in Sldf1[c(1, NA), ] : NAs not permitted in row index
149 >
150 > data(meuse.grid)
151 > gridded(meuse.grid) = ~x+y
152 > try(x <- meuse.grid[c(1:10,NA,12),])
153 Error in meuse.grid[c(1:10, NA, 12), ] : NAs not permitted in row index
154 > fullgrid(meuse.grid) = TRUE
155 > try(x <- meuse.grid[c(1:10,NA,12),])
156 Error in meuse.grid[c(1:10, NA, 12), ] : NAs not permitted in index
157 >
158 > try(x <- meuse[[c("zinc", "cadmium")]])
159 Error in .subset2(x, i, exact = exact) : subscript out of bounds
160 > try(meuse[[c("zn", "cd")]] <- cbind(meuse$zinc, meuse$cadmium))
161 Error in `[[<-`(`*tmp*`, i, value = value) : no such index at level 1
162
163 >
164 > data(meuse.grid)
165 > coordinates(meuse.grid) <- c("x", "y")
166 > gridded(meuse.grid) <- TRUE
167 > gridparameters(meuse.grid)
168 cellcentre.offset cellsize cells.dim
169 x 178460 40 78
170 y 329620 40 104
171 >
172 > image(meuse.grid)
173 > image(meuse.grid[2])
174 > image(meuse.grid, 2)
175 > try(image(meuse.grid, 0))
176 Error in .subset2(x, i, exact = exact) : subscript out of bounds
177 > image(meuse.grid[3], breaks=c(0,.2,.5,.8,1), col = bpy.colors(4))
178 > image(meuse.grid, 3, zlim = c(0,.3))
179 > image(meuse.grid, 3, zlim = c(.3,.1))
180 > image(meuse.grid, 3, zlim = c(.2,.8))
181 > image(meuse.grid, 3, zlim = c(.2,.8), breaks = c(.2,.4,.6,.8),
182 + col = bpy.colors(3))
183 >
184 > data(meuse.grid)
185 > set.seed(1)
186 > meuse.grid$x <- meuse.grid$x + rnorm(length(meuse.grid$x), 0, 0.0002)
187 > meuse.grid$y <- meuse.grid$y + rnorm(length(meuse.grid$y), 0, 0.0002)
188 > coordinates(meuse.grid) <- c("x", "y")
189 > try(gridded(meuse.grid) <- TRUE)
190 suggested tolerance minimum: 0.964318
191 Error in points2grid(points, tolerance, round) :
192 dimension 1 : coordinate intervals are not constant
193 > try(meuse.grid <- SpatialPixelsDataFrame(as(meuse.grid, "SpatialPoints"),
194 + data=as(meuse.grid, "data.frame"), tolerance=0.077))
195 > gridparameters(meuse.grid)
196 cellcentre.offset cellsize cells.dim
197 x 178460 39.99912 78
198 y 329620 39.99920 104
199 >
200 > data(meuse.grid_ll)
201 > try(gridded(meuse.grid_ll) <- TRUE)
202 suggested tolerance minimum: 0.818323
203 Error in points2grid(points, tolerance, round) :
204 dimension 1 : coordinate intervals are not constant
205 > try(meuse.grid_ll <- SpatialPixelsDataFrame(as(meuse.grid_ll, "SpatialPoints"), data=as(meuse.grid_ll, "data.frame"), tolerance=0.9))
206 > gridparameters(meuse.grid_ll)
207 cellcentre.offset cellsize cells.dim
208 x 5.721109 0.0005312853 84
209 y 50.955770 0.0003318105 112
210 >
211 > try(CRS("+proj=latlon +ellps=WGS84"))
212 Coordinate Reference System:
213 Deprecated Proj.4 representation: +proj=longlat +ellps=WGS84 +no_defs
214 WKT2 2019 representation:
215 GEOGCRS["unknown",
216 DATUM["Unknown based on WGS 84 ellipsoid",
217 ELLIPSOID["WGS 84",6378137,298.257223563,
218 LENGTHUNIT["metre",1],
219 ID["EPSG",7030]]],
220 PRIMEM["Greenwich",0,
221 ANGLEUNIT["degree",0.0174532925199433],
222 ID["EPSG",8901]],
223 CS[ellipsoidal,2],
224 AXIS["longitude",east,
225 ORDER[1],
226 ANGLEUNIT["degree",0.0174532925199433,
227 ID["EPSG",9122]]],
228 AXIS["latitude",north,
229 ORDER[2],
230 ANGLEUNIT["degree",0.0174532925199433,
231 ID["EPSG",9122]]]]
232 > try(CRS("+proj=lonlat +ellps=WGS84"))
233 Coordinate Reference System:
234 Deprecated Proj.4 representation: +proj=longlat +ellps=WGS84 +no_defs
235 WKT2 2019 representation:
236 GEOGCRS["unknown",
237 DATUM["Unknown based on WGS 84 ellipsoid",
238 ELLIPSOID["WGS 84",6378137,298.257223563,
239 LENGTHUNIT["metre",1],
240 ID["EPSG",7030]]],
241 PRIMEM["Greenwich",0,
242 ANGLEUNIT["degree",0.0174532925199433],
243 ID["EPSG",8901]],
244 CS[ellipsoidal,2],
245 AXIS["longitude",east,
246 ORDER[1],
247 ANGLEUNIT["degree",0.0174532925199433,
248 ID["EPSG",9122]]],
249 AXIS["latitude",north,
250 ORDER[2],
251 ANGLEUNIT["degree",0.0174532925199433,
252 ID["EPSG",9122]]]]
253 >
254 > proc.time()
255 user system elapsed
256 0.926 1.288 0.705