John
John

Reputation: 43279

Why does R not auto-complete data frame variables when subsetting

Using the data frame mtcars on RStudio.

Say for example I want to subset mtcars[mtcars$cyl == 4,]

Tabbing after mtcars$ will provide a drop down list of variable names in the data frame.

Tabbing after mtcars[mtcars$ does not return the variable names.

Why does this happen?

Upvotes: 2

Views: 1182

Answers (2)

JeremyS
JeremyS

Reputation: 3525

I was going to ask the same thing. I disagree with the answer that you are expecting R to look for something called mtcars[mtcars, because you can't even make that without putting it all in quotes anyway, e.g.

test[test <- c(1,3,2) # leaves you stuck with the next line being +

The only way to make such an abomination is:

"test[test" <- c(1,3,2)

And once made you still cant use

test[test[2]

You still need to use quotes

"test[test"[2]

So, as far as I can tell, tabbing after mtcars[mtcars$ failing is either a bug or has some sort of reason behind it. If there is a reason does anyone know what it is?

Upvotes: 2

user1317221_G
user1317221_G

Reputation: 15461

it will if you add a space:

mtcars[ mtcars$

otherwise your expecting r to look in something called mtcars[mtcars not mtcars...

Upvotes: 8

Related Questions