34

I have been adding columns to a data frame and using View() to check that it did what I expected. I have repeated lines of code along the lines of:

x$p <- 3 * x$a
x$q <- sqrt(x$b + x$c)
View(x)

This worked fine until the number of columns exceeded 100 (there are 47,000 rows). When I added another two columns, dim(x) shows 102 columns, names(x) shows 102 names, summary(x) shows summaries of all the expected columns. However, View(x) only displays the first 100 columns and doesn't display the last two added columns.

If I try View(x[,-(1:10)]) the most recently added columns are displayed.

I can't see any mention in the View documentation of a limit on the number of columns. Can anyone explain what is happening here?

dpel
  • 1,954
  • 1
  • 21
  • 31
Ross Gayler
  • 653
  • 1
  • 8
  • 14
  • 1
    Using RStudio? I guess so, since I see this problem with `x <- matrix(1:200,nrow=1); View(x)`, but not in vanilla R. They're working on it. Ref: http://support.rstudio.org/help/discussions/questions/181-view-more-than-first-100-columns – Frank Oct 13 '13 at 04:49
  • 1
    Yes - using RStudio. I was calling View from the command window rather than the environment browser because I suspected RStudio might be doing something odd, but thought using the command line would avoid it. RStudio must be aliasing view to limit the number of rows and columns. It tells you it is only showing the first 1000 rows. It would be nice if it did the same for columns. Thanks – Ross Gayler Oct 13 '13 at 04:55
  • Yeah, agreed. I quit using it as soon as I noticed the row limit (which didn't take long), but I'll likely go back if/when they improve the data browser (or enable the vanilla R one). You can contact the devs on their forum, I guess, to give your feedback. – Frank Oct 13 '13 at 04:57
  • 3
    I've contacted RStudio. I can live with the VIew limits now that I know. The thing that confused me is that RStudio tells you it is only showing the first 1,000 rows - so I assumed it would be consistent and tell me if it was dropping columns. – Ross Gayler Oct 13 '13 at 05:24
  • Yes, it doesn't support. See [here](http://support.rstudio.org/help/discussions/questions/850-display-more-than-1000-rows-of-dataframe-in-a-table-form-in-rstudio) – Metrics Oct 13 '13 at 14:06

6 Answers6

22

(Updated)

You can have View() open in one of the quadrants or in a separate notepad-ish window. It opens in the quadrant where my source code is displayed on my machine at work, and in another window on my machine at home. In the latter case, it displays >1k rows & >100 columns (I just checked).

I'm not sure how you can get this to change permanently, IIRC when I updated RStudio and ran View() the first time, a window popped up and asked me to choose what program I wanted to use to display the file. In one case I selected RStudio, and in the other case, I selected notepad. In both cases, the 'use this program by default from now on' radio button was selected; I have never seen this window since. If you can switch to displaying with notepad, you should be able to get out of this problem. However, short of a permanent change, you can get View() to display your data in a separate window using the code utils::View(). This approach works on my machine at work. Here is what it looks like:

enter image description here

Note that I am running RStudio version 0.97.248 on a Windows 7 machine.

Here is what it looks like on my home machine where it comes up in a new window automatically:

enter image description here

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
  • @gung Without actually testing this, "IIRC when I updated RStudio and ran View() the first time, a window popped up and asked me to choose what program I wanted to use to display the file" it sounds like a different issue than the one I raised. View() is a base R function for browsing an R object (e.g. a data frame) via a spreadsheet-like interface. It sounds like you were being asked to select a text-file editor. – Ross Gayler Oct 13 '13 at 23:32
  • I understand what `View()` is, I use it constantly. When I'm on my machine at home & I call `View()`, it pops up a window using notepad & allows me to browse the object there. But at work, it pops up in the same quadrant as my source code. – gung - Reinstate Monica Oct 13 '13 at 23:41
  • 1
    @gung I just typed `View` and `utils::View` into the command window in Rstudio and got two different outputs. It looks to me like Rstudio installs its own version of `View()` that masks `utils::View()`. The Rstudio version pops up in an Rstudio quadrant window, whereas the utils version pops up in a free floating window. Given that your home installation of Rstudio pops up a separate notepad window I wonder whether somehow the home installation has failed to install the Rstudio `View` hooks and is calling `utils::View` instead. – Ross Gayler Oct 21 '13 at 08:30
  • 1
    I think there are two problems with the viewer: 1. Only dataframes can be viewed, not vector, lists... 2. The viewer shows the content but you can't modify it. I think that simple feature addition would attract many people to use RStudio. You can use the console and type "edit(mydataframe)" , it would be great if that option was included on the aforementioned doubleclick action. Anyway it doesn't work well. You modify any cell and close the window but the new value isn't stored. – skan Oct 25 '15 at 21:00
14

I also see this problem with x <- matrix(1:200,nrow=1); View(x) in RStudio, but not in vanilla R. It is a known limitation and they're working on it. You can contact the devs on their forum to give your feedback (and have done so, I see).

Frank
  • 66,179
  • 8
  • 96
  • 180
8

I found a solution that worked for me in a closed RStudio Github issue. You can change the maximum number of columns displayed (say to 1000) using the following command:

rstudioapi::writeRStudioPreference("data_viewer_max_columns", 1000L)

You should be able to run this just once, and it will thereafter be saved to your settings file as the new default in every subsequent R session. Under my Linux system, these preferences are stored in ~/.config/rstudio/rstudio-prefs.json. The relevant line that the above command will add is:

"data_viewer_max_columns":1000
  • I wonder why this isn't the accepted answer. It's the most practical solution to the issue experienced by the asker. – Faustin Gashakamba Dec 01 '22 at 09:19
  • this is great! although the utils workaround suggested above is helpful, it wont display column position/num so this answer is what i was looking for – FishyFishies Jun 18 '23 at 17:14
7

I just ran into this issue also. As suggested by gung above, the utils::View() function is helpful as a workaround for browsing all available columns in a data frame, whereas Rstudio still defaults to only the first 100 available columns when using the View() function.

The workaround is very useful for identifying the column names for creating a subset from an existing data frame. However, it doesn't provide a quick column enumeration that the RStudio View() function allows. It's been a few years since the original post in 2013, but this limitation in the RStudio environment seems to still be effective in present-day 2017.

Ferdi
  • 540
  • 3
  • 12
  • 23
Paul Sochacki
  • 433
  • 6
  • 8
3

Try fix(). It loads all your columns and rows. The only problem is that it might take long to load large data frames.

AliCivil
  • 2,003
  • 6
  • 28
  • 43
0

I'm not sure if this has been mentioned before but I found this interesting post from 2012: https://support.rstudio.com/hc/en-us/community/posts/200669267-view-more-than-first-100-columns-.

This indexing allows you to at least check the other columns and if they even exist.

So just use: datafile[row-row, column-column].

dpel
  • 1,954
  • 1
  • 21
  • 31
Kevin
  • 1