Skip to content

mess(): multiple bugs in SpatVector branch; single-column data.frame handling #33

Description

@jeffery-leirness

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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions