stackinator
stackinator

Reputation: 5819

R Studio `F2` and `View()` producing two different results

df <- mtcars
View(df)

The code above results in the image below (what I expect) and also prints df <- mtcars and View(df) to my console.

enter image description here

If I then highlight df in my console and press F2 I get the image below. And nothing is output to my console.

enter image description here

F2 is supposed to be equivalent to View() and it usually is. Right now I can highlight mtcars, press F2, and I get the spreadsheet view. df is showing as a data.frame in my global environment, yet F2 thinks it is a function.

enter image description here

Why won't F2 work when I highlight this particular df that I just defined as df <- mtcars?

Upvotes: 1

Views: 144

Answers (1)

C. Braun
C. Braun

Reputation: 5201

There is also a built-in function called df from the stats package. Pressing f2 is primarily for showing the source code of a function, and will only do the equivalent of View if the variable is not a function.

If you really use this a lot you may need to use a different name for your variables.

Upvotes: 3

Related Questions