1
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?

stackinator
  • 5,429
  • 8
  • 43
  • 84
  • Also, why did you re-ask this question when you already received and accepted a well-worded answer? [duplicate](https://stackoverflow.com/questions/52655772/r-studio-f2-wont-initiate-view-anymore) – C. Braun Oct 05 '18 at 14:28
  • 3
    Using `df` as the name of a dataframe is [occasionally problematic in other ways](https://stackoverflow.com/q/50163004/4996248). Having said that, I still do it all the time. Old habits are hard to break. – John Coleman Oct 05 '18 at 14:29
  • 2
    @C.Braun I agree that this is a duplicate although it was probably intended more as a follow up. The problem is that the accepted answer falsely suggests that *after* you define `df` as a dataframe, then `F2` will revert to `View(df)`. It doesn't. – John Coleman Oct 05 '18 at 14:35

1 Answers1

3

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.

C. Braun
  • 5,061
  • 19
  • 47