-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Passing expressions as columns to pivot_longer
fails with error.
#118
Comments
@etiennebacher is this an issue in the new version? |
This is not related to suppressPackageStartupMessages(library(poorman))
d = data.frame(X=1:5, Y1=runif(5), Y2=runif(5))
nd = names(d)[-1]
rename_with(d, toupper, nd)
#> X Y1 Y2
#> 1 1 0.89690835 0.7336885
#> 2 2 0.60126522 0.8331964
#> 3 3 0.03632217 0.9804623
#> 4 4 0.09652256 0.2674726
#> 5 5 0.51158470 0.5940056
rename_with(d, toupper, names(d)[-1])
#> Error in (function (.data, ..., .group_pos = FALSE) : Locations Y1 and Y2 don't exist. There are only 3 columns. Created on 2022-11-02 with reprex v2.0.2 |
Can be fixed by adding if (is.character(pos)) {
pos <- which(data_names %in% pos)
} just after this line: Line 38 in e910fd7
|
Looks like an env issue with https://github.com/nathaneastwood/poorman/blob/master/R/select_positions.R#L183-L185 |
Maybe related: suppressPackageStartupMessages(library(poorman))
iris <- head(iris, n = 1)
# Works
for (i in names(iris)) {
print(select(iris, all_of(i)))
}
#> Sepal.Length
#> 1 5.1
#> Sepal.Width
#> 1 3.5
#> Petal.Length
#> 1 1.4
#> Petal.Width
#> 1 0.2
#> Species
#> 1 setosa
# Doesn't work
lapply(names(iris), function(x) {
select(iris, all_of(x))
})
#> Error in x %in% vars: object 'x' not found Created on 2022-11-21 with reprex v2.0.2 |
Describe the bug
Running pivot_longer with column names specified in a vector with
c("Y1","Y2")
works fine, but if an expression returns that vector it fails.To Reproduce
Sample data:
I want to pivot longer on all vars except the first one. The names are therefore:
and this works
but this doesn't:
I could simply do
pivot_longer(d, -1)
but there are maybe other contexts where an expression might get passed to cols, eg some function that returns the columns:Expected behavior
The two pivot_longer calls should return the same data frame.
System Information:
Please detail the following information
R.version.string
is [1] "R version 4.1.1 (2021-08-10)"packageVersion("poorman")
is 0.2.6The text was updated successfully, but these errors were encountered: