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

fix: relocate() works when .before and .after called in a function #114

Closed

Conversation

etiennebacher
Copy link
Contributor

Close #110. I didn't use the code you put in #110 because it didn't seem to work. Maybe my solution can be simplified.

myFun <- function(location_before = NULL, location_after = NULL) {
  poorman::relocate(head(mtcars), gear, .before = location_before, .after = location_after)
}
myFun()
#>                   gear  mpg cyl disp  hp drat    wt  qsec vs am carb
#> Mazda RX4            4 21.0   6  160 110 3.90 2.620 16.46  0  1    4
#> Mazda RX4 Wag        4 21.0   6  160 110 3.90 2.875 17.02  0  1    4
#> Datsun 710           4 22.8   4  108  93 3.85 2.320 18.61  1  1    1
#> Hornet 4 Drive       3 21.4   6  258 110 3.08 3.215 19.44  1  0    1
#> Hornet Sportabout    3 18.7   8  360 175 3.15 3.440 17.02  0  0    2
#> Valiant              3 18.1   6  225 105 2.76 3.460 20.22  1  0    1
myFun(location_before = 2)
#>                    mpg gear cyl disp  hp drat    wt  qsec vs am carb
#> Mazda RX4         21.0    4   6  160 110 3.90 2.620 16.46  0  1    4
#> Mazda RX4 Wag     21.0    4   6  160 110 3.90 2.875 17.02  0  1    4
#> Datsun 710        22.8    4   4  108  93 3.85 2.320 18.61  1  1    1
#> Hornet 4 Drive    21.4    3   6  258 110 3.08 3.215 19.44  1  0    1
#> Hornet Sportabout 18.7    3   8  360 175 3.15 3.440 17.02  0  0    2
#> Valiant           18.1    3   6  225 105 2.76 3.460 20.22  1  0    1
myFun(location_after = 2)
#>                   gear  mpg cyl disp  hp drat    wt  qsec vs am carb
#> Mazda RX4            4 21.0   6  160 110 3.90 2.620 16.46  0  1    4
#> Mazda RX4 Wag        4 21.0   6  160 110 3.90 2.875 17.02  0  1    4
#> Datsun 710           4 22.8   4  108  93 3.85 2.320 18.61  1  1    1
#> Hornet 4 Drive       3 21.4   6  258 110 3.08 3.215 19.44  1  0    1
#> Hornet Sportabout    3 18.7   8  360 175 3.15 3.440 17.02  0  0    2
#> Valiant              3 18.1   6  225 105 2.76 3.460 20.22  1  0    1

Created on 2022-08-27 by the reprex package (v2.0.1)

Only works if the argument passed are numeric.

@codecov-commenter
Copy link

Codecov Report

Merging #114 (54fdb68) into master (bbb9aed) will decrease coverage by 0.08%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##           master     #114      +/-   ##
==========================================
- Coverage   93.53%   93.45%   -0.09%     
==========================================
  Files          58       58              
  Lines        1455     1467      +12     
==========================================
+ Hits         1361     1371      +10     
- Misses         94       96       +2     
Impacted Files Coverage Δ
R/relocate.R 94.44% <85.71%> (-5.56%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@etiennebacher
Copy link
Contributor Author

My fix fails when using column names e.g df %>% relocate(a, .after = c). There must be a cleaner way to fix this.

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.

relocate() doesn't work when .before and .after are provided a variable inside a function
2 participants