Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create_PLANTS() for #71 #72

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions R/create_PLANTS.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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)
}
Loading