diff --git a/NAMESPACE b/NAMESPACE index aad6bd37ff..7e491cb0c7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(create_KST) export(create_KST13) export(create_NSSH) export(create_OSD) +export(create_PLANTS) export(get_assets) export(get_create_functions) export(logmsg) @@ -15,6 +16,7 @@ export(validateOSD) importFrom(curl,curl_download) importFrom(curl,new_handle) importFrom(data.table,data.table) +importFrom(data.table,fread) importFrom(dplyr,bind_rows) importFrom(jsonlite,read_json) importFrom(jsonlite,toJSON) diff --git a/R/create_PLANTS.R b/R/create_PLANTS.R new file mode 100644 index 0000000000..25a42316ea --- /dev/null +++ b/R/create_PLANTS.R @@ -0,0 +1,28 @@ +# create PLANTS snapshot +# +#' Create PLANTS Dataset +#' +#' @param ... Arguments to `create_*()` function. Only `outpath` supported at this time. +#' @return TRUE if successful +#' @export +#' @importFrom data.table fread +create_PLANTS <- function(...) { + + args <- list(...) + if (!is.null(args[["outpath"]])) { + outpath <- args[["outpath"]] + } + + 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) +} diff --git a/man/create_PLANTS.Rd b/man/create_PLANTS.Rd new file mode 100644 index 0000000000..b6f11ab50e --- /dev/null +++ b/man/create_PLANTS.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/create_PLANTS.R +\name{create_PLANTS} +\alias{create_PLANTS} +\title{Create PLANTS Dataset} +\usage{ +create_PLANTS(...) +} +\arguments{ +\item{...}{Arguments to `create_*()` function. Only `outpath` supported at this time.} +} +\value{ +TRUE if successful +} +\description{ +Create PLANTS Dataset +}