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

cutData can overwrite earlier created columns with unexpected data #404

Open
mooibroekd opened this issue Dec 22, 2024 · 0 comments
Open
Labels
bug Bugs in the current release of openair

Comments

@mooibroekd
Copy link

Bug description

Today I tracked down a bug where the 'year' column in my data was a bit strange. It turns out that cutData overwrites the data when a particular order is used to create columns.

Steps to reproduce

packageVersion("openair")
#> [1] '2.18.2'

# create some date data for illustration
test <- data.frame(date = seq.Date(lubridate::date("2022-01-01"), 
                                   lubridate::date("2022-12-31"), 
                                   by = 1))

# cut the data into years
test <- openair::cutData(test, type = "year")

# check if we have any dates that are associated with 2023
test |>
  dplyr::filter(year == 2023)
#> [1] date year
#> <0 rows> (or 0-length row.names)

# now cut the data to yearseason
test <- openair::cutData(test, type = "yearseason")

# perform the test again:
test |>
  dplyr::filter(year == 2023)
#>          date year       season month          yearseason
#> 1  2022-12-01 2023 winter (DJF)    12 winter (DJF) - 2023
#> 2  2022-12-02 2023 winter (DJF)    12 winter (DJF) - 2023
#> 3  2022-12-03 2023 winter (DJF)    12 winter (DJF) - 2023
#> 4  2022-12-04 2023 winter (DJF)    12 winter (DJF) - 2023
#> 5  2022-12-05 2023 winter (DJF)    12 winter (DJF) - 2023
#> 6  2022-12-06 2023 winter (DJF)    12 winter (DJF) - 2023
#> 7  2022-12-07 2023 winter (DJF)    12 winter (DJF) - 2023
#> 8  2022-12-08 2023 winter (DJF)    12 winter (DJF) - 2023
#> 9  2022-12-09 2023 winter (DJF)    12 winter (DJF) - 2023
#> 10 2022-12-10 2023 winter (DJF)    12 winter (DJF) - 2023
#> 11 2022-12-11 2023 winter (DJF)    12 winter (DJF) - 2023
#> 12 2022-12-12 2023 winter (DJF)    12 winter (DJF) - 2023
#> 13 2022-12-13 2023 winter (DJF)    12 winter (DJF) - 2023
#> 14 2022-12-14 2023 winter (DJF)    12 winter (DJF) - 2023
#> 15 2022-12-15 2023 winter (DJF)    12 winter (DJF) - 2023
#> 16 2022-12-16 2023 winter (DJF)    12 winter (DJF) - 2023
#> 17 2022-12-17 2023 winter (DJF)    12 winter (DJF) - 2023
#> 18 2022-12-18 2023 winter (DJF)    12 winter (DJF) - 2023
#> 19 2022-12-19 2023 winter (DJF)    12 winter (DJF) - 2023
#> 20 2022-12-20 2023 winter (DJF)    12 winter (DJF) - 2023
#> 21 2022-12-21 2023 winter (DJF)    12 winter (DJF) - 2023
#> 22 2022-12-22 2023 winter (DJF)    12 winter (DJF) - 2023
#> 23 2022-12-23 2023 winter (DJF)    12 winter (DJF) - 2023
#> 24 2022-12-24 2023 winter (DJF)    12 winter (DJF) - 2023
#> 25 2022-12-25 2023 winter (DJF)    12 winter (DJF) - 2023
#> 26 2022-12-26 2023 winter (DJF)    12 winter (DJF) - 2023
#> 27 2022-12-27 2023 winter (DJF)    12 winter (DJF) - 2023
#> 28 2022-12-28 2023 winter (DJF)    12 winter (DJF) - 2023
#> 29 2022-12-29 2023 winter (DJF)    12 winter (DJF) - 2023
#> 30 2022-12-30 2023 winter (DJF)    12 winter (DJF) - 2023
#> 31 2022-12-31 2023 winter (DJF)    12 winter (DJF) - 2023

# reason why this is happening is because the winter is defined from december 
# yyyy to march yyyy+1.
# I would suspect cutData to only return the yearseason, not the year and season
# columns (or overwrite them if they exists.)

Created on 2024-12-22 with reprex v2.1.1

Openair version

No response

@mooibroekd mooibroekd added the bug Bugs in the current release of openair label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs in the current release of openair
Projects
None yet
Development

No branches or pull requests

1 participant