extract_coords_combine {dynamicSDM}R Documentation

Combine extracted explanatory variable data for occurrence records into single data frame.

Description

Combines the split output files from functions extract_dynamic_coords() and extract_buffered_coords() into single data frame containing all occurrence records and explanatory variables.

Usage

extract_coords_combine(
  varnames,
  local.directory,
  set_class = FALSE,
  col_classes
)

Arguments

varnames

a character string, the unique names for each explanatory variable.

local.directory

a character string or vector, the path to local directory or directories to read extracted explanatory data frames from.

set_class

a logical indicating whether to set the classes of each column in the data before merging to avoid error. See details for more information.

col_classes

optional; a named vector specifying the classes for columns within occ.data.

Details

When functions extract_dynamic_coords() and extract_buffered_coords() have been used to extract dynamic explanatory variables for occurrence records, the output for individual records and each variable will be split into separate “csv” files.

This function reads in these files and combines data into a single data frame containing each occurrence records and associated explanatory data from each variable.

To prevent error, the “csv” files must be uniquely named within the folder(s) and include an exact character match for the varnames provided. All “csv” files matching the varnames should have the same number and names of columns. This is the default output ofextract_dynamic_coords() and extract_buffered_coords().

Value

Returns a data frame containing all occurrence records with associated explanatory variable data.

Column classes

When co-ordinate data have been extracted using the split method in extract_dynamic_coords() and extract_buffered_coords(), sometimes the classes of columns in the separate exported data frames can vary. For instance, one split row may contain an NA value in one column, whilst another split contains a numerical value. When extract_coords_combine() attempts to read these in and bind them together, an error can occur due to the class mismatch (logical compared to numeric).

There are two arguments that can help to resolve this error:

Examples


data(sample_filt_data)


dynamicSDM::extract_dynamic_coords(
 occ.data = sample_filt_data,
 datasetname = "UCSB-CHG/CHIRPS/DAILY",
 bandname = "precipitation",
 spatial.res.metres = 10000,
 GEE.math.fun = "sum",
 temporal.direction = "prior",
 temporal.res = 56,
 save.method = "split",
 varname = "eightweekprec",
 save.directory = tempdir()
)
dynamicSDM::extract_dynamic_coords(
 occ.data = sample_filt_data,
 datasetname = "UCSB-CHG/CHIRPS/DAILY",
 bandname = "precipitation",
 spatial.res.metres = 10000,
 GEE.math.fun = "sum",
 temporal.direction = "prior",
 temporal.res = 364,
 save.method = "combined",
 varname = "annualweekprec",
 save.directory = tempdir()
)

extract_coords_combine(varnames = c("eightweekprec", "annualweekprec"),
                      local.directory = tempdir(),
                      set_class = TRUE,
                      col_classes = c(sapply(sample_filt_data,class),
                                    eightweekprec = "numeric",
                                    annualweekprec="numeric"))


[Package dynamicSDM version 1.3.4 Index]