Open
Description
Describe the bug
Some plot()
methods do not anticipate subclasses of sfc objects. This makes it difficult to write extensions to the sf package.
To Reproduce
Here's an example with a linestring.
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
l <- st_linestring(matrix(c(0, 1, 0, 1), ncol = 2))
s <- st_sfc(l)
plot(s)
class(s) <- c("subclass", class(s))
class(s)
#> [1] "subclass" "sfc_LINESTRING" "sfc"
Failure:
try(plot(s))
#> Error in eval(expr, envir, enclos) :
#> Not compatible with STRSXP: [type=NULL].
The error is not because of the call to plot_sf()
, although that plot is empty; it's because of the call to st_is_empty()
, which seems to not be expecting subclasses:
plot_sf(s)
try(st_is_empty(s))
#> Error in eval(expr, envir, enclos) :
#> Not compatible with STRSXP: [type=NULL].
Created on 2024-08-31 with reprex v2.1.0
Additional context
sessionInfo()
#> R version 4.3.3 (2024-02-29)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Monterey 12.6
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: America/Vancouver
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] styler_1.10.3 digest_0.6.36 fastmap_1.2.0 xfun_0.45
#> [5] magrittr_2.0.3 glue_1.7.0 R.utils_2.12.3 knitr_1.47
#> [9] htmltools_0.5.8.1 rmarkdown_2.27 lifecycle_1.0.4 cli_3.6.3
#> [13] R.methodsS3_1.8.2 vctrs_0.6.5 reprex_2.1.0 withr_3.0.0
#> [17] compiler_4.3.3 R.oo_1.26.0 R.cache_0.16.0 purrr_1.0.2
#> [21] rstudioapi_0.16.0 tools_4.3.3 evaluate_0.24.0 yaml_2.3.8
#> [25] rlang_1.1.4 fs_1.6.4
sf::sf_extSoftVersion()
#> GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H
#> "3.11.0" "3.5.3" "9.1.0" "true" "true"
#> PROJ
#> "9.1.0"
packageVersion("sf")
#> [1] '1.0.16'
Created on 2024-08-31 with reprex v2.1.0