Creates a data.frame of species' references from files in a directory
Source:R/pam_helpers.R
files_2data.Rd
Creates a data.frame of species' references that contains longitude, latitude, and species name, from a character.
Arguments
- 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
path
. Current available formats are: "shp", "gpkg", "GTiff", and "ascii".- spdf_grid
geographic grid for the region of interest (output of function
grid_from_region
). Used when format equals "shp" or "gpkg". Default = NULL.- parallel
(logical) whether to perform analyses in parallel. Default = FALSE.
- n_cores
(numeric) number of cores to be used when
parallel
= TRUE. The default, NULL, uses available cores - 1.
Value
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".
Examples
# \donttest{
# 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)
#>
|
| | 0%
|
|=== | 4%
|
|====== | 8%
|
|========= | 12%
|
|============ | 17%
|
|=============== | 21%
|
|================== | 25%
|
|==================== | 29%
|
|======================= | 33%
|
|========================== | 38%
|
|============================= | 42%
|
|================================ | 46%
|
|=================================== | 50%
|
|====================================== | 54%
|
|========================================= | 58%
|
|============================================ | 62%
|
|=============================================== | 67%
|
|================================================== | 71%
|
|==================================================== | 75%
|
|======================================================= | 79%
|
|========================================================== | 83%
|
|============================================================= | 88%
|
|================================================================ | 92%
|
|=================================================================== | 96%
|
|======================================================================| 100%
# }