Skip to content

bbox class is not detectable in S4 methods #2448

@sigmafelix

Description

@sigmafelix

st_bbox() output has class that is reported when class() is run, however, when a S4 method tries to utilize this information, I encounter a "no definition for class bbox" error.

Reproducible example

library(sf)
dd <- st_bbox(c(xmin = 16.1, xmax = 16.6, ymax = 48.6, ymin = 47.9), crs = st_crs(4326))
class(dd)
[1] "bbox"

setGeneric("detect_bbox", function(x){})
[1] "detect_bbox"
setMethod("detect_bbox", signature = c(x = "bbox"), function(x){class(x)})
# in method for ‘detect_bbox’ with signature ‘x="bbox"’: no definition for class “bbox”

With sf class object, S4 method works properly:

library(sf)
ncsf_path <- system.file("shape/nc.shp", package = "sf")
ncsf <- st_read(ncsf_path)

setGeneric("detect_sf_col", function(x){})
setMethod("detect_sf_col", signature = c(x = "sf"), function(x) names(x))
detect_sf_col(ncsf)
# [1] "AREA"      "PERIMETER" "CNTY_"     "CNTY_ID"   "NAME"      "FIPS"
# [7] "FIPSNO"    "CRESS_ID"  "BIR74"     "SID74"     "NWBIR74"   "BIR79"
#[13] "SID79"     "NWBIR79"   "geometry"

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