R/misc.R

Defines functions simFile

Documented in simFile

#' @keywords internal
.ageClassCutOffs <- c(0, 40, 80, 120)

#' @keywords internal
.ageClasses <- c("Young", "Immature", "Mature", "Old")

#' Extract study area name from run name
#'
#' @param area Simulated area (i.e., run) name
#'
#' @export
cleanAreaName <- Vectorize(function(area) {
  strsplit(area, "_")[[1]] %>%
    grep("Dispersal|ROS", ., invert = TRUE, value = TRUE) %>%
    paste(., collapse = "_")
})

#' Generate simulation file name
#'
#' Assists with saving/retrieving LandWeb simulations.
#'
#' @param name Object name (e.g., \code{"mySimOut"})
#' @param path Directory location in where the file will be located (e.g., an \code{outputPath}).
#' @param time Optional simulation time to use as filename suffix. Default \code{NULL}.
#' @param ext  The file extension to use (default \code{"rds"}).
#' @export
#' @importFrom SpaDES.core paddedFloatToChar
#' @importFrom reproducible normPath
simFile <- function(name, path, time = NULL, ext = "rds") {
  if (is.null(time))
    file.path(normPath(path), paste0(name, ".", ext))
  else {
    file.path(normPath(path), paste0(name, "_", paddedFloatToChar(time, padL = 4), ".", ext))
  }
}
PredictiveEcology/LandWebUtils documentation built on Sept. 12, 2020, 11:14 p.m.