Sampbias is a method and tool to 1) visualize the distribution of occurrence records and species in any user-provided dataset, 2) quantify the biasing effect of geographic features related to human accessibility, such as proximity to cities, rivers or roads, and 3) create publication-level graphs of these biasing effects in space.
33
stars
9
forks
source link
Error when `restrict_sample` is a `SpatVector` #16
calculate_bias() throws an error when restrict_sample is supplied and is a SpatVector (the help indicates it should be a SpatVector). Adapted from the example for that function:
x <- data.frame(species = rep(sample(x = LETTERS, size = 5), times = 20),
decimalLongitude = runif(n = 100, min = 0, max = 20),
decimalLatitude = runif(n = 100, min = -4, max = 4))
x_vect <- terra::vect(x, geom = names(x)[2:3], crs = 'EPSG:4326')
restrict_sample <- terra::buffer(x_vect, 20000)
out <- calculate_bias(x, terrestrial = TRUE, buffer = 0, restrict_sample = restrict_sample)
Error: unable to find an inherited method for function ‘vect’ for signature ‘x = "SpatVector"’
Note that restrict_sample should be able to take a SpatVector, as per the help: @param restrict_sample a \code{SpatVector} object.
This line:
restrict_sample <- terra::vect(restrict_sample)
assumes restrict_sample is not a SpatVector, so throws the error.
This only converts restrict_sample to a SpatVector if needed:
if (!inherits(restrict_sample, 'SpatVector')) restrict_sample <- terra::vect(restrict_sample)
This now works:
out <- calculate_bias(x, terrestrial = TRUE, buffer = 0, restrict_sample = restrict_sample)
calculate_bias()
throws an error whenrestrict_sample
is supplied and is aSpatVector
(the help indicates it should be aSpatVector
). Adapted from the example for that function:Note that
restrict_sample
should be able to take aSpatVector
, as per the help:@param restrict_sample a \code{SpatVector} object.
This line:
restrict_sample <- terra::vect(restrict_sample)
assumes
restrict_sample
is not aSpatVector
, so throws the error.This only converts
restrict_sample
to aSpatVector
if needed:if (!inherits(restrict_sample, 'SpatVector')) restrict_sample <- terra::vect(restrict_sample)
This now works:
out <- calculate_bias(x, terrestrial = TRUE, buffer = 0, restrict_sample = restrict_sample)