-
Notifications
You must be signed in to change notification settings - Fork 97
Peaks and Ratings #888
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
Peaks and Ratings #888
Changes from all commits
0baddb0
20fd8f6
7584089
aa4a2a6
d8d7f5d
62c1934
05f34a4
dbb4a15
7b4a49b
3fd9f76
6d6a8f0
2ee9add
753b674
8d92a4c
66fe712
00b2d08
04b555a
b600173
e3402e8
021b11e
8d20e65
feae5d1
e5d1150
13cdba8
252873c
e193c38
df780f2
2bcb219
27ee733
beecb34
1eb8d80
d9b148b
458c92c
f9d1c71
75df7a5
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 |
|---|---|---|
|
|
@@ -71,3 +71,5 @@ vignettes/Reference_Lists.Rmd | |
| ^[.]?air[.]toml$ | ||
| ^\.vscode$ | ||
| environment.yml | ||
| ^\.positai$ | ||
| ^\.claude$ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,4 @@ vignettes/*.html | |
| vignettes/*.R | ||
| /.quarto/ | ||
| **/*.quarto_ipynb | ||
| .positai | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,7 +340,7 @@ switch_arg_id <- function(ls, id_name, service) { | |
| #' dataRetrieval:::format_api_dates(end) | ||
| #' dataRetrieval:::format_api_dates(end, TRUE) | ||
| #' | ||
| #' end <- c(NA, as.POSIXct("2021-01-01 12:15:00")) | ||
| #' end <- as.POSIXct(c(NA, "2021-01-01 12:15:00")) | ||
| #' dataRetrieval:::format_api_dates(end) | ||
| #' | ||
| #' start_end <- as.POSIXct(c("2021-01-01 12:15:00", | ||
|
|
@@ -370,38 +370,57 @@ switch_arg_id <- function(ls, id_name, service) { | |
| #' start <- "2025-10-01" | ||
| #' end <- Sys.Date() | ||
| #' dataRetrieval:::format_api_dates(c(start, end), date = TRUE) | ||
| #' | ||
| #' # This is a problem because the first value forces the | ||
| #' # vector to be numeric, and then we don't really | ||
| #' # know if the 2nd value is a Date (number of days since 1970) | ||
| #' # or if it's a date/time (number of seconds..) | ||
| #' half_range <- c(NA, as.Date("2025-01-01")) | ||
| #' # Will error: | ||
| #' #dataRetrieval:::format_api_dates(half_range, date = FALSE) | ||
| #' # Better way to do it: | ||
| #' better_half <- as.Date(c(NA, "2025-01-01")) | ||
| #' dataRetrieval:::format_api_dates(better_half, date = FALSE) | ||
| format_api_dates <- function(datetime, date = FALSE) { | ||
| if (is.character(datetime)) { | ||
| datetime[datetime == ""] <- NA | ||
| datetime <- toupper(datetime) | ||
| } | ||
|
|
||
| if (all(is.na(datetime))) { | ||
| return(NA) | ||
| } | ||
|
|
||
| if (all(is.null(datetime))) { | ||
| if (all(is.na(datetime)) | all(is.null(datetime))) { | ||
| return(NA) | ||
| } | ||
|
|
||
| if (length(datetime) > 2) { | ||
| stop("datetime should only include 1-2 values") | ||
| } | ||
|
|
||
| if (is.numeric(datetime)) { | ||
| # Until we can figure out a way to know if the | ||
| # original input was suppose to be Date or Posix | ||
| # We can't determine what the user meant. | ||
| stop( | ||
| "A time query was entered as numeric. This could lead to errors. | ||
|
Collaborator
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. The only way I can think to do this would be to check the expression passed within the function call, but that gets into
Collaborator
Author
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 think most workflows I've seen are using that use characters, Date objects, or POSIX. All of those are fine, and any numeric is unintentional. So I'm comfortable leaving this as an error. I assume the time it will come up most is something like: df <- read_waterdata_sample(some stuff)
df_range <- range(df$time)
cont_df <- read_waterdata_daily(time = c(NA, df_range[2])If we plaster examples and tutorials with stuff like: cont_df <- read_waterdata_continuous(time = as.Date(c(NA, df_range[2]))I think we'll be OK.
Collaborator
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. That sounds like a good plan. |
||
| Check any time queries that might have been automatically converted to numeric. | ||
| This could happen if you use c(NA, as.Date(Sys.Date())) instead of | ||
| as.Date(c(NA, Sys.Date()) for example." | ||
| ) | ||
| } | ||
|
|
||
| if (length(datetime) == 1) { | ||
| # If the user has "P" or the "/" we assume they know what they are doing | ||
| if ( | ||
| grepl("P", datetime, ignore.case = TRUE) | | ||
| grepl("/", datetime) | ||
| ) { | ||
| return(datetime) | ||
| } | ||
|
|
||
| if (date) { | ||
| datetime <- get_Date(datetime) | ||
| } else { | ||
| if (date) { | ||
| datetime <- get_Date(datetime) | ||
| } else { | ||
| datetime1 <- get_dateTime(datetime) | ||
| datetime <- lubridate::format_ISO8601(datetime1, usetz = "Z") | ||
| } | ||
| datetime1 <- get_dateTime(datetime) | ||
| datetime <- lubridate::format_ISO8601(datetime1, usetz = "Z") | ||
| } | ||
| } else if (length(datetime) == 2) { | ||
| if (date) { | ||
|
|
||
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.
This didn't error for me, but it did appear to interpret as a numeric timestamp, meaning I got
"../1970-01-01T05:34:49Z"as outputThere 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.
I wonder if I pushed the "stop" command up after you pulled? I get: