2

For some weird reason, RStudio is showing me all columns of a data.frame when I use the View() function or when I click on a data frame in the environment pane. I installed a new version of R three weeks ago (because I have a new Windows10 laptop) and since then I am running into this problem.

This is really annoying because R becomes super slow when having to display more than 100 columns. Random example of code

a=data.frame(replicate(1000,sample(0:1,10,rep=TRUE)))
View(a)

In the good old days, only the first 100 columns were displayed...

Any ideas on how to change this back to normal?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
BeSeLuFri
  • 623
  • 1
  • 5
  • 21
  • 2
    R doesn't have a "Data Viewer" or an "environment pane". I'm guessing you are having difficulties with Rstudio functions that you are misattributing to R. You need to be more specific about versions and code if you expect an informed response. – IRTFM Feb 14 '18 at 16:44
  • Ok, sry. I meant RStudio. But it is really a general problem I am having. Lets say I have a data frame of 1000 columns and then the View function should only display the first 100 columns. But it doesn't... It is showing all of them. Example code given above now. – BeSeLuFri Feb 14 '18 at 16:49
  • The `?View` page in base R makes no mention of a default limit on the number of columns displayed (at least in my version of R 3.4.3 running on a Mac. So in addition to not providing a clear question, you are now apparently expressing expectations with an unclear basis. – IRTFM Feb 14 '18 at 17:05
  • 2
    What's wrong with `View(df[,1:100])`? You could very easily define a custom `View()` function in R that only does a subset. – David Klotz Feb 14 '18 at 17:08
  • @42- I didn't know about the limit of `View` either until I find this: [Using the Data Viewer - Restrictions and Performance](https://support.rstudio.com/hc/en-us/articles/205175388-Using-the-Data-Viewer#restrictions-and-performance) – ytu Feb 14 '18 at 17:15
  • I think this is great news, my Rstudio displays only 100 columns and it's a pain, it means this is solved: https://stackoverflow.com/questions/19341853/r-view-does-not-display-all-columns-of-data-frame – moodymudskipper Feb 14 '18 at 17:32
  • Ths suggests to me that the Rstudio `View` function is different than the one that ships with regular R. It also means that it is doubly important, even imperative, that you post full details about versions of R and Rstudio. – IRTFM Feb 14 '18 at 19:08
  • Sorry for the slow response. Here are the details platform x86_64-w64-mingw32 minor 4.4 svn rev 74408 language R version.string R version 3.4.4 (2018-03-15) Under the 3.4.4 I have the same problem as before. However I am just following @DavidKlotz advice and use View(df[, c("a","b") ]) – BeSeLuFri Mar 27 '18 at 14:09
  • Like I suggested earlier, you can also define a custom function, or even overwrite the RStudio one: `View <- function(x) View(x[,1:100]).` Then try `View(df)`. Not a practice I would recommend in general, but if this is really an issue for you maybe it's worth trying out. – David Klotz Mar 27 '18 at 16:19

2 Answers2

2

I have this problem with long dataframes of > 300000 rows. The RStudio session will freeze if I View() the df. Unfortunately I often use View() to check my results but I often forget to make sure the df isn't too large. To prevent this I have written a function as recommended in the comments above. I spent a bit of time figuring out how to get the name to show up like with View() so I thought I would share it.

RStudioView <- View
View <- function(x) {
  name  <- deparse(substitute(x))
  if ("data.frame" %in% class(x)) { 
    RStudioView(x[1:1000,], name)
    } else { 
    RStudioView(x) 
    }
}

Based on a function found here. You could just change it to limit columns instead of rows and set whatever cutoff works best for you.

see24
  • 1,097
  • 10
  • 21
0

You can view a selected list of columns, like this:

df <- data.frame(a = c(1,2), b = c(1,2), c = c(1,2))
View(df[, c("a","b") ])

If this still takes a long time to render, look to see that you have the latest RStudio release. There was recently a bug where RStudio was slow to read Windows networked drives, and it affects the View() function. It's fixed in the latest RStudio release, apparently.

Incidentally, I rarely use View() anymore. I now work in RMarkdown notebooks, which automatically renders a snapshot of the dataset in a paged and easy to read format that accomodates large datasets with no problem. And I haven't run into any latency issues here.

Stuart
  • 131
  • 1
  • 4
  • do you stil have a link to this discussion about RStudio being slow to read Windows networked drives? I suffer from this a lot but I was blaming my company's network. edit : found it! https://github.com/rstudio/rstudio/issues/1592 – moodymudskipper Feb 14 '18 at 17:36
  • But why does the View() function show all columns now anyways? As it was limited earlier to 100 columns. Can I somehow get back to View() just showing 100 columns automatically? – BeSeLuFri Feb 15 '18 at 14:02