-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Allow glue-styled pattern for data_rename()
#563
Conversation
@DominiqueMakowski @easystats/core-team any suggestions for further patterns? |
the many rd-files are just due to lintr-updates, can be ignored when reviewing this PR. |
data_rename()
data_rename()
I added some more options: library(datawizard)
data(mtcars)
out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "formerly_{col}")
head(out)
#> formerly_mpg formerly_cyl formerly_disp
#> Mazda RX4 21.0 6 160
#> Mazda RX4 Wag 21.0 6 160
#> Datsun 710 22.8 4 108
#> Hornet 4 Drive 21.4 6 258
#> Hornet Sportabout 18.7 8 360
#> Valiant 18.1 6 225
out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "{col}_is_column_{n}")
head(out)
#> mpg_is_column_1 cyl_is_column_2 disp_is_column_3
#> Mazda RX4 21.0 6 160
#> Mazda RX4 Wag 21.0 6 160
#> Datsun 710 22.8 4 108
#> Hornet 4 Drive 21.4 6 258
#> Hornet Sportabout 18.7 8 360
#> Valiant 18.1 6 225
out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "new_{letter}")
head(out)
#> new_a new_b new_c
#> Mazda RX4 21.0 6 160
#> Mazda RX4 Wag 21.0 6 160
#> Datsun 710 22.8 4 108
#> Hornet 4 Drive 21.4 6 258
#> Hornet Sportabout 18.7 8 360
#> Valiant 18.1 6 225
x <- c("hi", "there", "!")
out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "col_{x}")
head(out)
#> col_hi col_there col_!
#> Mazda RX4 21.0 6 160
#> Mazda RX4 Wag 21.0 6 160
#> Datsun 710 22.8 4 108
#> Hornet 4 Drive 21.4 6 258
#> Hornet Sportabout 18.7 8 360
#> Valiant 18.1 6 225
data_rename(mtcars[1:3], c("mpg", "disp"), "col_{x}")
#> Error: The number of values provided in `{x}` (3 values) do not match the
#> number of the columns to rename (2 columns). Created on 2024-11-24 with reprex v2.1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Could we use |
I don't think it matters because it's only recognized when inside |
I think it's even less problematic: the |
I wasn't sure how you had implemented the {} and whether it was evaluating the names inside {} (like glue does) |
Created on 2024-11-21 with reprex v2.1.1