Check if a R object or a filename correspond to a valid vector object, to a vector file or none of the above. Useful to detect which kind of input is passed to a function and abort / do something in the case of "wrong" input.

get_vectype(in_vect, abort = TRUE)

Arguments

in_vect

name of an R object, or character giving the full path to a vector file

abort

If TRUE, and in_vect is neither a spatial object or filename, send an error message and abort, Default: TRUE

Value

character equal to "vectfile" (if in_vect is a raster file), spobject (if in_vect is of class spatial), sfobject (if in_vect is of class sf), or NA if it is neither (unless abort == TRUE)

Examples

# input is a shapefile in_vect <- system.file("extdata/shapes","lc_polys.shp", package = "sprawl.data") get_vectype(in_vect)
#> [1] "vectfile"
# input is a `sp` object obj <- read_vect(in_vect, as_sp = TRUE) get_vectype(obj)
#> [1] "spobject"
# input is a `sf` object obj <- read_vect(in_vect) get_vectype(obj)
#> [1] "sfobject"
# input is a `sprawlext` object obj <- get_extent(in_vect) get_vectype(obj)
#> [1] "sprawlext"