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

Bug: change() errors with dates #85

Closed
andrewallenbruce opened this issue May 10, 2024 · 1 comment
Closed

Bug: change() errors with dates #85

andrewallenbruce opened this issue May 10, 2024 · 1 comment
Assignees
Labels
bug 💣 an unexpected problem or unintended behavior

Comments

@andrewallenbruce
Copy link
Owner

library(tidyverse)
library(provider)
library(clock)

# Fine
provider:::gen_data(2020:2025) |> 
  provider::change(pay)
#> # A tibble: 12 × 6
#>     year group   pay pay_chg  pay_pct pay_ror
#>    <int> <chr> <int>   <int>    <dbl>   <dbl>
#>  1  2020 A      1576       0  0         1    
#>  2  2021 A      1204    -372 -0.236     0.764
#>  3  2022 A      1192     -12 -0.00997   0.990
...

# Errors on dates
tibble(
  date = c(
    date_build(2023, 12), 
    date_build(2024, 1:5)
  ),
  total = c(
    1132783.09,
    942482.25,
    949739.89,
    985444.69,
    888797.41,
    808376.95
  )) |> 
  provider::change(total)
#> Error in `dplyr::mutate()`:
#> ℹ In argument: `dplyr::across(...)`.
#> Caused by error in `across()`:
#> ! Can't compute column `date`.
#> Caused by error in `Math.Date()`:
#> ! sign not defined for "Date" objects

# <date> is a double
is.double(date_build(2023, 12))
#> [1] TRUE

# but is not numeric
is.numeric(date_build(2023, 12))
#> [1] FALSE

Error is on line 88, here:

dplyr::mutate(
   dplyr::across(
   dplyr::where(is.double), <-- Here
    ~janitor::round_half_up(., digits = digits)))

Created on 2024-05-10 with reprex v2.1.0

@andrewallenbruce andrewallenbruce added the bug 💣 an unexpected problem or unintended behavior label May 10, 2024
@andrewallenbruce andrewallenbruce self-assigned this May 10, 2024
@andrewallenbruce
Copy link
Owner Author

Removed the call to janitor::round_half_up(); rounding at point of data retrieval questionable anyway:

library(tidyverse)
library(clock)
library(provider)

tibble(
  date = c(
    date_build(2023, 12), 
    date_build(2024, 1:5)
  ),
  total = c(
    1132783.09,
    942482.25,
    949739.89,
    985444.69,
    888797.41,
    808376.95
  )) |> 
  provider::change(total)
#> # A tibble: 6 × 5
#>   date          total total_chg total_pct total_ror
#>   <date>        <dbl>     <dbl>     <dbl>     <dbl>
#> 1 2023-12-01 1132783.        0    0           1    
#> 2 2024-01-01  942482.  -190301.  -0.168       0.832
#> 3 2024-02-01  949740.     7258.   0.00770     1.01 
#> 4 2024-03-01  985445.    35705.   0.0376      1.04 
#> 5 2024-04-01  888797.   -96647.  -0.0981      0.902
#> 6 2024-05-01  808377.   -80420.  -0.0905      0.910

Created on 2024-05-13 with reprex v2.1.0

andrewallenbruce added a commit that referenced this issue May 14, 2024
* fix: failing tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 💣 an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant