-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 mutate() to choose the position of new columns #2047
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
To me, that seems overly complicated. I think 90% of the time people just want variables to go in the front, instead of in the back. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If we're only interested in supporting adding to the front, maybe we could use @lionel-: What would it take to make the following syntax work? library(tidyverse)
tibble(a = 2, b = 3) %>% transmute(x = 1, everything())
#> Error in mutate_impl(.data, dots): Evaluation error: No tidyselect variables were registered.
|
This comment has been minimized.
This comment has been minimized.
Agreed, but Users might be tempted to do the following (I have no idea why the second occurrence of library(tidyverse)
iris %>% transmute(Species, !!!.) %>% head()
#> Species Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1 setosa 5.1 3.5 1.4 0.2
#> 2 setosa 4.9 3.0 1.4 0.2
#> 3 setosa 4.7 3.2 1.3 0.2
#> 4 setosa 4.6 3.1 1.5 0.2
#> 5 setosa 5.0 3.6 1.4 0.2
#> 6 setosa 5.4 3.9 1.7 0.4
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This is important when developing data transformation pipes: Especially after a I wonder if we could attach an attribute to the result of Sketch: library(tidyverse)
options(width = 60)
iris %>%
as_tibble() %>%
mutate(Sepal.Area = Sepal.Width * Sepal.Length)
#> # A tibble: 150 x 4
#> Sepal.Length Sepal.Width Petal.Length | Sepal.Area
#> <dbl> <dbl> <dbl> | <dbl>
#> 1 5.1 3.5 1.4 | 17.8
#> 2 4.9 3 1.4 | 14.7
#> 3 4.7 3.2 1.3 | 15.0
#> 4 4.6 3.1 1.5 | 14.3
#> 5 5 3.6 1.4 | 18
#> 6 5.4 3.9 1.7 | 21.1
#> 7 4.6 3.4 1.4 | 15.6
#> 8 5 3.4 1.5 | 17
#> 9 4.4 2.9 1.4 | 12.8
#> 10 4.9 3.1 1.5 | 15.2
#> # ... with 140 more rows, and 2 more variables:
#> # Petal.Width <dbl>, Species <fct>
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If we support automatic splicing of unnamed data frames (named ones would be added as df-cols), and data %>% transmute(new = foo, sels(everything()) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It may be worth considering that the primary reason to put variables on the left is so you can see them in the default display. It's possible that a better fix for the underlying issue would also be to show some columns on the far right (i.e. elide columns in the middle, not on the right) |
I think it would be a very useful default to display the first and last few columns in stead of just the first few. I've had to use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
In MySQL we have two verbs, first and after , to add a column in a table with alter. Maybe dplyr can copy that behavior? It could also solve #4598. |
I'm once again leaning towards a |
Discussion of dedicated move verb at #4598 You can now use df %>%
transmute(x = y ^ 2, across(everything()) |
before
and after
arguments to mutate()
@hadley, this is a great commit, but perhaps it should support multiple columns relocation (the thread title is indeed Allow mutate() to choose the position of new columns):
produces
and not
|
@courtiol Your suggestion would not work with plural selections like |
I agree @lionel-, but it would make sense in mutate() calls without suffix (as shown above), wouldn't it? |
These arguments would specify the position where the new columns are inserted, before or after some column given as index or name.
See also tidyverse/tibble#99.
The text was updated successfully, but these errors were encountered: