-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fix for #87 — force update_datetime
to be a datetime
#88
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -689,6 +689,18 @@ npn_get_data_by_year <- function(endpoint, | |
#' @returns A tibble of the requested data. If a `download_path` was specified, | ||
#' the file path is returned. | ||
#' @keywords internal | ||
#' @examples \dontrun{ | ||
#' npn_get_data( | ||
#' url = "https://services.usanpn.org/npn_portal//observations/getObservations.ndjson?", | ||
#' query = list( | ||
#' request_src = "Unit%20Test", | ||
#' climate_data = "0", | ||
#' `species_id[1]` = "6", | ||
#' start_date = "2010-01-01", | ||
#' end_date = "2010-12-31" | ||
#' ) | ||
#' ) | ||
#' } | ||
npn_get_data <- function(url, | ||
query, | ||
download_path = NULL, | ||
|
@@ -719,10 +731,22 @@ npn_get_data <- function(url, | |
promote_num_to_string = TRUE) %>% | ||
tibble::as_tibble() %>% | ||
#replace missing data indicator with NA | ||
dplyr::mutate(dplyr::across(dplyr::where(is.numeric), | ||
\(x) ifelse(x == -9999, NA_real_, x))) %>% | ||
dplyr::mutate(dplyr::across(dplyr::where(is.character), | ||
\(x) ifelse(x == "-9999", NA_character_, x))) | ||
dplyr::mutate( | ||
dplyr::across(dplyr::where(is.numeric), | ||
function(x) ifelse(x == -9999, NA_real_, x)) | ||
) %>% | ||
dplyr::mutate( | ||
dplyr::across(dplyr::where(is.character), | ||
function(x) ifelse(x == "-9999", NA_character_, x)) | ||
) %>% | ||
#handle some columns that may be read in as the wrong type if they happen | ||
#to be all NAs (#87). `any_of()` is used because not all endpoints will | ||
#return these columns! | ||
dplyr::mutate( | ||
dplyr::across(dplyr::any_of("update_datetime"), | ||
function(x) as.POSIXct(x, tz = "UTC")), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what the timezone should be here or if it matters. Could also just make this column character and leave it up to the user to figure out the timezone if they care. |
||
dplyr::across(dplyr::any_of("intensity_value"), as.character) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found that this column is sometimes numbers, but also sometimes things like "3 to 10". Do you happen to know if |
||
) | ||
|
||
# Reconcile all the points in the frame with the SIX leaf raster, | ||
# if it's been requested. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from
\(x)
tofunction(x)
is because the shorthand\(x)
is only available in more recent versions of R, but defines an anonymous function identically tofunction(x)