While reviewing the mess() implementation in mess.R, I found four confirmed correctness bugs. This issue and the linked PR were developed with assistance from an AI coding assistant (Posit Assistant / Claude).
Confirmed bugs
-
Undefined object p in SpatVector geometry check (line 37) The geometry check uses geomtype(p), but p is not defined in that scope. It should be geomtype(v). As written, passing a non-point SpatVector as v throws object 'p' not found rather than the intended informative error.
-
extract() arguments reversed in SpatVector branch (line 39) extract(v, x) has its arguments in the wrong order. The correct call is extract(x, v, ID = FALSE). Using ID = FALSE also avoids the need to manually drop the ID column that terra::extract() prepends by default.
-
Reference matrix v not coerced after extract() (line 41) terra::extract() returns a data frame. The downstream code (particularly .messi(), which calls sort()) expects a vector or matrix. Adding v <- as.matrix(v) after na.omit() fixes this and also makes the function more robust to data frame input from any source.
-
Single-column data.frame method passes whole object to .messi() (line 94) In the data.frame method, data.frame(mess = .messi(x, v)) passes the entire data frame to .messi(), which expects vector inputs. This should be .messi(x[, 1], v[, 1]).
Patch
A working branch has all four bugs fixed and a new tests/testthat/test-mess.R covering each case (9 tests, all passing). See linked PR.
While reviewing the mess() implementation in mess.R, I found four confirmed correctness bugs. This issue and the linked PR were developed with assistance from an AI coding assistant (Posit Assistant / Claude).
Confirmed bugs
Undefined object p in SpatVector geometry check (line 37) The geometry check uses geomtype(p), but p is not defined in that scope. It should be geomtype(v). As written, passing a non-point SpatVector as v throws object 'p' not found rather than the intended informative error.
extract() arguments reversed in SpatVector branch (line 39) extract(v, x) has its arguments in the wrong order. The correct call is extract(x, v, ID = FALSE). Using ID = FALSE also avoids the need to manually drop the ID column that terra::extract() prepends by default.
Reference matrix v not coerced after extract() (line 41) terra::extract() returns a data frame. The downstream code (particularly .messi(), which calls sort()) expects a vector or matrix. Adding v <- as.matrix(v) after na.omit() fixes this and also makes the function more robust to data frame input from any source.
Single-column data.frame method passes whole object to .messi() (line 94) In the data.frame method, data.frame(mess = .messi(x, v)) passes the entire data frame to .messi(), which expects vector inputs. This should be .messi(x[, 1], v[, 1]).
Patch
A working branch has all four bugs fixed and a new tests/testthat/test-mess.R covering each case (9 tests, all passing). See linked PR.