-
Notifications
You must be signed in to change notification settings - Fork 115
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
cutData()
refinements
#407
Open
jack-davison
wants to merge
8
commits into
master
Choose a base branch
from
feat-cutData-refinement
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+542
−515
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- roxygen2md - crosslinks - remove incorrect items
- drop weird dups ("site" and "ws" aren't special) - use lubridate where possible - move everything to testable functions
Examples: devtools::load_all()
#> ℹ Loading openair
dat <- head(openair::mydata) |> dplyr::select(date, no2, o3)
cutData(dat)
#> # A tibble: 6 × 4
#> date no2 o3 default
#> <dttm> <int> <int> <fct>
#> 1 1998-01-01 00:00:00 39 1 01 January 1998 to 01 January 1998
#> 2 1998-01-01 01:00:00 NA NA 01 January 1998 to 01 January 1998
#> 3 1998-01-01 02:00:00 NA 3 01 January 1998 to 01 January 1998
#> 4 1998-01-01 03:00:00 52 3 01 January 1998 to 01 January 1998
#> 5 1998-01-01 04:00:00 78 2 01 January 1998 to 01 January 1998
#> 6 1998-01-01 05:00:00 42 0 01 January 1998 to 01 January 1998
cutData(dat, names = c("limits"))
#> # A tibble: 6 × 4
#> date no2 o3 limits
#> <dttm> <int> <int> <fct>
#> 1 1998-01-01 00:00:00 39 1 01 January 1998 to 01 January 1998
#> 2 1998-01-01 01:00:00 NA NA 01 January 1998 to 01 January 1998
#> 3 1998-01-01 02:00:00 NA 3 01 January 1998 to 01 January 1998
#> 4 1998-01-01 03:00:00 52 3 01 January 1998 to 01 January 1998
#> 5 1998-01-01 04:00:00 78 2 01 January 1998 to 01 January 1998
#> 6 1998-01-01 05:00:00 42 0 01 January 1998 to 01 January 1998
cutData(dat, c("o3", "no2", "weekday"), names = c("o3_breaks", "no2_cuts", "wday"))
#> Warning: ! Removing 1 rows due to missing `o3` data.
#> Warning: ! Removing 1 rows due to missing `no2` data.
#> # A tibble: 4 × 6
#> date no2 o3 o3_breaks no2_cuts wday
#> <dttm> <int> <int> <fct> <fct> <ord>
#> 1 1998-01-01 00:00:00 39 1 o3 0 to 1 no2 39 to 41.2 Thursday
#> 2 1998-01-01 03:00:00 52 3 o3 2 to 3 no2 47 to 58.5 Thursday
#> 3 1998-01-01 04:00:00 78 2 o3 1 to 2 no2 58.5 to 78 Thursday
#> 4 1998-01-01 05:00:00 42 0 o3 0 to 1 no2 41.2 to 47 Thursday
cutData(dat, c("o3", "no2", "weekday"), suffix = c("_cuts"))
#> Warning: ! Removing 1 rows due to missing `o3` data.
#> ! Removing 1 rows due to missing `no2` data.
#> # A tibble: 4 × 6
#> date no2 o3 o3_cuts no2_cuts weekday
#> <dttm> <int> <int> <fct> <fct> <ord>
#> 1 1998-01-01 00:00:00 39 1 o3 0 to 1 no2 39 to 41.2 Thursday
#> 2 1998-01-01 03:00:00 52 3 o3 2 to 3 no2 47 to 58.5 Thursday
#> 3 1998-01-01 04:00:00 78 2 o3 1 to 2 no2 58.5 to 78 Thursday
#> 4 1998-01-01 05:00:00 42 0 o3 0 to 1 no2 41.2 to 47 Thursday
cutData(dat, c("o3", "nox"), suffix = c("_cuts"))
#> Warning: ! Removing 1 rows due to missing `o3` data.
#> Error:
#> ✖ type 'nox' is neither a built-in option, nor a column in x.
#> ℹ Built-ins: default, year, hour, month, season, week, weekday, wd, weekend,
#> monthyear, yearmonth, bstgmt, gmtbst, dst, daylight, seasonyear, and
#> yearseason
#> ℹ Names in x: date, no2, o3, and o3_cuts Created on 2025-01-31 with reprex v2.1.1 |
jack-davison
added
enhancement
Ideas for new features for openair
utilities 🛠
Openair data utilities, e.g., timeAverage
labels
Feb 1, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
Ideas for new features for openair
utilities 🛠
Openair data utilities, e.g., timeAverage
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This supersedes #406 but would fix #404 and a bit more.
This is a rewrite for
cutData()
to make it more modern and less destructive, and clean up legacy code that wasn't going anywhere.Features
Added
names
which defines the column names appended to the data.Added
suffix
, an alternative tonames
, which will append a suffix to any column that would overwrite an existing column.The function will now error if you feed it something that is neither a column nor an in-built function.
The function now consistently messages if it filters your data.
Refactoring/Fixes
All of the different in-built functions now operate on vectors and exist in child functions. This makes them easier to test, and stops them from being as destructive.
We're already importing lubridate, so we're now using lubridate for other stuff (e.g., weekdays). It already deals with things like different weekdays in different locales, for example.
Dropped the idea of adding an "openair" source attribute.
Dropped the special treatment of "site" - there was seemingly nothing special about it.
Dropped documentation references to "ws", which I don't think has ever been treated specially by
cutData()