R/create_PLANTS.R

Defines functions parse_PLANTS create_PLANTS

Documented in create_PLANTS

# create PLANTS snapshot
#
#' Create PLANTS Dataset
#'
#' @param ... Arguments to `parse_PLANTS()` function. Only `outpath` supported at this time.
#' @return `TRUE` if successful
#' @export
#' @importFrom data.table fread
create_PLANTS <- function(...) {
  parse_PLANTS(...)
}
parse_PLANTS <- function(outpath = "inst/extdata", ...) {

  x <- data.table::fread('https://plants.usda.gov/assets/docs/CompletePLANTSList/plantlst.txt')

  d <- file.path(outpath, "PLANTS")
  f <- file.path(d, "plantlst.csv")

  if (!dir.exists(d)) {
    dir.create(d, showWarnings = FALSE)
  }

  res <- try(write.csv(x, f, row.names = FALSE,))

  !inherits(res, 'try-error') && file.exists(f)
}
brownag/SoilKnowledgeBase documentation built on April 5, 2025, 1:32 a.m.