-
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
Somewhat unexpected "invalid subscript type 'double'" when using $ #1554
Comments
I've been having this same issue also, and I agree that the problem is hard to debug at first, before you realize what's going on. Here's a stack overflow post I made before seeing this bug report: I've also had this issue at least once in the past when I was trying to extract a function from an object, and the function happened to have the same name as a different function on the search path (while doing this inside a |
Interesting. Also, the thread suggests a good workaround by quoting the field name: someVariable <- list(a = 3, b = 5)
a <- 10
dplyr::mutate(mtcars, newColumn = someVariable$'a') %>% head |
Another stackoverflow reference: http://stackoverflow.com/questions/21598295/how-to-debug-invalid-subscript-type-integer-error-in-r |
I just got bit by this issue as well. |
Duplicate of #1400 |
When ‘y’ was present global environment, an error (“invalid subscript type 'double’”) would be generated by dplyr. See tidyverse/dplyr#1554.
Dear all,
I wanted to add a new column to a data frame with a constant value from a list:
This works.
But if a variable of the same name ("a") is present, I get an error:
A fix consists in encapsulating the offending call with I():
(edit: this fix might not be advisable as
newColumn
is of classAsIs
and not of the expecteddouble
. To avoid the issue, simply store the value into a new variable and use this new variable instead ofsomeVariable$a
in the call todplyr::mutate
.)This is reminiscent of bug #421 , which is closed.
Whether it's something to fix or not, I leave it up to you but it was a bit maddening to debug (in my case, the variable 'a' was only sometimes present in the global environment, so my tests were passing when run from a separate environment, but not always when run from the console.).
thanks.
The text was updated successfully, but these errors were encountered: