Reputation: 1013
I had this snippet of working code:
number_of_columns <- dim(resultsper)[2]
resultsper <- resultsper %>% gather(c(5:number_of_columns), key = "Scenario", value = "Value")
This used to work fine, but now, I get the message
Error in FUN(X[[i]], ...) : object 'number_of_columns' not found.
If I run
resultsper <- resultsper %>% gather <- (c(5:11), key = "Scenario", value = "Value")
It works again, but this is not what I want. I tried gather_ but this also doesn't work. It might be an update of tidyr, but I haven't found a solution yet.
Thanks in advance
Renger
Upvotes: 1
Views: 1894
Reputation: 36076
Starting in tidyr 0.7.0, selecting rules are more strict. A review of all the changes in versino 0.7.0 can be found in this article.
In a nutshell, when using a context expression (i.e., using information outside the dataset) you must be explicit on where to find the objects by using the quasiquotation operator !!
.
Here is an example of what that would look like in your scenario.
number_of_columns = ncol(mtcars)
mtcars %>% gather("Scenario", "Value", !! 5:number_of_columns)
Upvotes: 1