Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Error: names() applied to a non-vector

Tags:

I have a chunk of code which produces an error only the first time I run it. Strangely if I run it a second time I get no error (craziness definition?). Also the error does not show up always at the same position, I mean that if I add a few lines of comments the error message is printed after the comments and not after a specific instruction.

I cannot provide a reproducible example because I do not know where exactly the error comes from. The error is the following:

Error in names(frame)[names(frame) == "x"] <- name :    names() applied to a non-vector 

I should specify that in my code I don't have -at least explicitly- a names() function.

like image 831
Manfredo Avatar asked Sep 21 '16 09:09

Manfredo


Video Answer


1 Answers

This is a tricky error. I was able to track down the reason and it seems to be that R has an object of the same name as the function cached. This is most likely if using an IDE such as RStudio a tab for View(df). Unless the tab is closed even running the function without code will give you this error. Likewise, if the tab is not closed not even removing all objects or doing a garbage collection will solve it. Once the tab is closed the error will be gone.

like image 180
José Bayoán Santiago Calderón Avatar answered Sep 17 '22 12:09

José Bayoán Santiago Calderón