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

addins for boilerplate and merge refactor groups + {poof} tricks #9

Open
moodymudskipper opened this issue Oct 6, 2021 · 0 comments

Comments

@moodymudskipper
Copy link
Owner

Addins would replace code by %refactor_*% calls with rm()boilerplate if relevant.
We should also have an addin to merge refactored code by call type, non refactored code would be integrated on both sides if it's between calls of same type.

This is a good use case for {poof} action groups too, they should be built on top of addins.

  {
    # MoM change
    series_vol_1_mom <- smooth_series(series_vol_1, 1)
    series_vol_2_mom <- smooth_series(series_vol_2, 1)
  } %refactor_chunk% {
    series_vol_1_mom <- map_dfc(series_vol_1, ~ . / lag(.) - 1)
    series_vol_2_mom <- map_dfc(series_vol_2, ~ . / lag(.) - 1)
    # ~ for {refactor}:
    series_vol_1_mom <- as.data.frame(series_vol_1_mom)
    series_vol_2_mom <- as.data.frame(series_vol_2_mom)
  }

  {
    series_vol_1_cum <- moving_sum(series_vol_1_mom, 12, 0)
    series_vol_2_cum <- moving_sum(series_vol_2_mom, 12, 0)
  } %refactor_chunk% {
    series_vol_1_cum <- map_dfc(series_vol_1_mom, roll::roll_sum, 12)
    series_vol_2_cum <- map_dfc(series_vol_2_mom, roll::roll_sum, 12)
    # ~ for {refactor}:
    series_vol_1_cum <- as.data.frame(series_vol_1_cum)
    series_vol_2_cum <- as.data.frame(series_vol_2_cum)
  }

==>

  {
    # MoM change
    series_vol_1_mom <- smooth_series(series_vol_1, 1)
    series_vol_2_mom <- smooth_series(series_vol_2, 1)

    series_vol_1_cum <- moving_sum(series_vol_1_mom, 12, 0)
    series_vol_2_cum <- moving_sum(series_vol_2_mom, 12, 0)
  } %refactor_chunk% {
    series_vol_1_mom <- map_dfc(series_vol_1, ~ . / lag(.) - 1)
    series_vol_2_mom <- map_dfc(series_vol_2, ~ . / lag(.) - 1)

    series_vol_1_cum <- map_dfc(series_vol_1_mom, roll::roll_sum, 12)
    series_vol_2_cum <- map_dfc(series_vol_2_mom, roll::roll_sum, 12)
    # ~ for {refactor}:
    series_vol_1_mom <- as.data.frame(series_vol_1_mom)
    series_vol_2_mom <- as.data.frame(series_vol_2_mom)

    series_vol_1_cum <- as.data.frame(series_vol_1_cum)
    series_vol_2_cum <- as.data.frame(series_vol_2_cum)
  }

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

No branches or pull requests

1 participant