prepare_dataset is the workhorse function for creating portalcasting rodent datasets using existing functions.
Wraps around portalr::summarize_rodent_data to produce a data.frame associated with a set of data specifications. Inputs are ready for implementation via prepare_rodents. prepare_rodents creates specified datasets using their associated function (typically prepare_dataset) and arguments, according to the directory_settings. prepare_abundance creates a model-ready vector of abundances for fitting and casting, according to the model's requirements and time settings.
Usage
prepare_abundance(main = ".", dataset = NULL, species = NULL, model = NULL)
prepare_rodents(
main = ".",
datasets = prefab_datasets(),
new_datasets_controls = NULL
)
prepare_dataset(
name = "all",
main = ".",
filename = "rodents_all.csv",
clean = FALSE,
level = "Site",
type = "Rodents",
plots = "all",
unknowns = FALSE,
shape = "crosstab",
time = "newmoon",
output = "abundance",
fillweight = FALSE,
treatment = NULL,
na_drop = FALSE,
zero_drop = FALSE,
min_traps = 1,
min_plots = 24,
effort = TRUE,
species = prefab_species(main = main),
total = TRUE,
save = TRUE
)
read_datasets_controls(main = ".")
datasets_controls(main = ".", datasets = NULL)
write_datasets_controls(
main = ".",
new_datasets_controls = NULL,
datasets = prefab_datasets()
)Arguments
- main
charactervalue of the name of the main component of the directory tree.- dataset, datasets
charactervalue(s) of name(s) of rodent dataset(s) to include.- species
character-valued vector of species names to include.- model
charactervalue of the model name.- new_datasets_controls
Optional
listof controls for new datasets. Seedatasets_controls.- name
charactername to be given to the dataset.- filename
charactervalue of the file for saving the output.- clean
logicalindicator of if only the rodent data that passed QA/QC (clean = TRUE) or if all data (clean = FALSE) should be loaded.- level
characterindicating the type of summary:"Plot","Treatment", or"Site". Pipes directly toportalr::summarize_rodent_data.- type
charactervalue of the rodent data set type, according to pre-existing definitions. An alternative toggle tospecies.
Either all species (type = "Rodents") or only granivoes (type = "Granivores").- plots
Specification of subset of plots. Can be a vector of
numericplots indicators or specific sets indicated bycharactervalues:"all"plots or"Longterm"plots (plots that have had the same treatment for the entire time series).- unknowns
logicalindicator to either remove all individuals not identified to species (unknowns = FALSE) or sum them in an additional column (unknowns = TRUE.- shape
charactervalue indicating a "crosstab" or "flat" output.- time
charactervalue specifying the format of the time index in the output. Options are"period"(sequential Portal surveys),"newmoon"(lunar cycle numbering), and"date"(calendar date).
The defaulttime = "newmoon"produces an equispaced observation timestep, a common format format for discrete-time modeling.- output
characterindicating the type of data:"abundance","biomass", or"energy".- fillweight
logicalspecifier of whether to fill in unknown weights with other records from that individual or species, where possible.- treatment
characterindicating the specific treatment(s) to trim to iflevel = "Treatment":"control","exclosure","removal", or"spectabs"- na_drop
logicalindicator of ifNAvalues (representing insufficient sampling) should be dropped.- zero_drop
logicalindicator of if0values (representing sufficient sampling but no detection) should be dropped.- min_traps
integer(or integernumeric) of the minimum number of traps collected for a plot to be used.- min_plots
integer(or integernumeric) of the minimum number of plots surveyed for a survey to be used.- effort
logicalindicator of if the effort columns should be included in the output.- total
logicalvalue indicating if a total (sum across species should be added or not. Only available if more than one species is included.- save
logicalindicator controlling if the output should be saved out.
Value
prepare_dataset: data.frame for the specified dataset. prepare_rodents: list of data.frames for the specified datasets. prepare_abundance: numeric vector of abundance data corresponding to the time articulated in the metadata file. Missing values are interpolated if requested via the model controls. read_datasets_controls, write_datasets_controls, datasets_controls: list of datasets' control lists, invisible-ly for write_datasets_controls.
See also
Content preparation functions:
directory filling,
prepare covariates,
prepare metadata,
prepare models,
prepare newmoons
Examples
if (FALSE) { # \dontrun{
main1 <- file.path(tempdir(), "rodents")
create_dir(main = main1)
fill_resources(main = main1)
fill_forecasts(main = main1)
fill_fits(main = main1)
fill_models(main = main1)
prepare_newmoons(main = main1)
prepare_rodents(main = main1)
write_datasets_controls(main = main1)
read_datasets_controls(main = main1)
datasets_controls(main = main1)
unlink(main1, recursive = TRUE)
} # }