-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Description
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
Labels
No labels