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

Parameterize key query fields in riem_measures() #48

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

JElchison
Copy link

Expose key query fields in riem_measures() as parameters, including:

  • data (defaults to all as before)
  • elev (defaults to no as before)
  • latlon (defaults to yes as before)
  • report_type (new default is 3,4, which skips HFMETAR)

Update date_start to have safer default (2024 instead of 2014). Specify missing nometa query field. Update comments, self-documentation, and lintr exceptions accordingly.

@JElchison JElchison marked this pull request as draft December 16, 2024 20:18
@JElchison JElchison marked this pull request as ready for review December 16, 2024 20:38
Copy link
Member

@maelle maelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

R/measures.R Outdated Show resolved Hide resolved
R/measures.R Outdated Show resolved Hide resolved
R/measures.R Outdated Show resolved Hide resolved
R/measures.R Outdated
latlon = "yes",
date_start = "2024-01-01",
date_end = as.character(Sys.Date()),
# skip HFMETAR by default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why, by the way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, the IEM download page defaults to routine and specials, but not HFMETAR. They describe their rationale:

When in doubt, pick both routine and specials.

It seems to me that IEM is specifying their desired default behavior. Tangential, I've also found this IEM news article.

Second, there is a bandwidth/size penalty (9.1x) and time penalty (6.4x) when selecting HFMETAR. It seems like an unsafe default.

I compared two single data points:

  1. Link, 2.1 MB in 597ms
  2. Link, 19.1MB in 3820ms

I'm sure our friends at IEM would appreciate the bandwidth savings from users who don't really need HFMETAR.

Third, as a token consumer of this data, my specific application is hampered by the extra time required to download HFMETAR data ... but I'd be happy to set a parameter if I actually needed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it makes sense!

R/measures.R Show resolved Hide resolved
R/measures.R Outdated Show resolved Hide resolved
@JElchison JElchison marked this pull request as draft December 17, 2024 15:29
@JElchison JElchison marked this pull request as ready for review December 17, 2024 16:17
@JElchison
Copy link
Author

Ready for review, pending my outstanding question on default value for latlon. Thanks!

@JElchison
Copy link
Author

I'm unsure what your standard practice is, but I'll leave it to you to click "Resolve conversation" on any items resolved to your liking. Thanks!

@maelle
Copy link
Member

maelle commented Dec 19, 2024

@JElchison Thank you!! I made a few changes

  • use of rlang::is_character() since the package is importing rlang anyway.
  • made report_type hopefully more readable.
  • added some tests.

I have two requests for you:

  • do you agree with these changes?
  • I was not able to find a test case for "report_type". Could you help? It also might be that my refactoring of report_type's handling inadvertently broke it.

Afterwards I'll update the NEWS file and will plan a new release in January. Thanks again!

@@ -1,9 +1,15 @@
#' Get weather data from one station
#'
#' @importFrom rlang `%||%`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing here and here, should these backticks be removed? I'm uncertain about the nuance of backticks vs. double-quotes.

@@ -7,4 +7,5 @@ importFrom(jsonlite,read_json)
importFrom(magrittr,"%>%")
importFrom(rlang,"!!!")
importFrom(rlang,"%||%")
importFrom(rlang,`%||%`)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line duplicative of the previous? (See comment below.) I'm uncertain about the nuance of backticks vs. double-quotes.


report_type <- report_type %||% c("routine", "specials")
report_type <- tolower(report_type) # not case-sensitive
report_type <- rlang::arg_match(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your use of a map to abstract away the literals!

One side effect of rlang::arg_match(multiple = TRUE), however, is that the error message can be misleading in terms of the number required:

! `report_type` must be one of "hfmetar", "routine", or "specials", not "3,4".

It's the one of that throws me for a mild loop. I wonder if we could reduce any misleading by making line 12 a more clear comment, perhaps:

#' @param report_type A vector of strings, representing report types to query. The available options are "hfmetar", "routine", "specials". Default value is c("routine", "specials"). # nolint: line_length_linter

@JElchison
Copy link
Author

  • do you agree with these changes?

Yes, they look good! I asked a couple clarifying questions as comments.

  • I was not able to find a test case for "report_type". Could you help? It also might be that my refactoring of report_type's handling inadvertently broke it.

Yes, will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants