Skip to content

Commit

Permalink
Add create_PLANTS() for #71
Browse files Browse the repository at this point in the history
  • Loading branch information
brownag committed Nov 29, 2023
1 parent 8720775 commit 25ab739
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions R/create_PLANTS.R
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 17 additions & 0 deletions man/create_PLANTS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25ab739

Please sign in to comment.