| files_2data | R Documentation |
Creates a data.frame of species' references that contains longitude, latitude, and species name, from a character.
files_2data(path, format, spdf_grid = NULL, parallel = FALSE, n_cores = NULL)
path |
(character) full path name of directory containing raster, shapefiles or geopackage files representing species geographic ranges. Each file must be named as the species that it represents. All files must be in the same format. If files are raster layers, values in each layer must be 1 (presence, suitable) and 0 (absence, unsuitable). |
format |
(character) the format files found in |
spdf_grid |
geographic grid for the region of interest (output of
function |
parallel |
(logical) whether to perform analyses in parallel. Default = FALSE. |
n_cores |
(numeric) number of cores to be used when |
If files are in raster format, a data.frame of species geographic records derived from values of presence in each layer.
If files are not in raster format, a data.frame of species' found in distinct positions (defined with identifiers); includes two columns: "ID" and "Species".
# Data for examples
mx <- terra::vect(system.file("extdata/mx.gpkg", package = "biosurvey"))
species_data <- terra::vect(system.file("extdata/species_data.gpkg",
package = "biosurvey"))
# Saving species data in a temporal directory
tdir <- file.path(tempdir(), "testbio")
dir.create(tdir)
namessp <- unique(species_data$Species)
for (i in 1:length(species_data)) {
terra::writeVector(species_data[species_data$Species == namessp[i], ],
filename = paste0(tdir, "/", namessp[i], ".gpkg"))
}
# Preparing grid for analysis
grid_reg <- grid_from_region(region = mx, cell_size = 100)
# Running analysis with data from directory
sp_data <- files_2data(path = tdir, format = "gpkg", spdf_grid = grid_reg)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.