View() an entire dataset in RStudio (past 1000 row limit) - r

Simple question but I can't figure it out in RStudio:
View(mydata) only gives me 1000 rows.
How can I increase this limit to a number of my choosing? Say, like 25,000?

It is not View() but also works in command-line R:
options(max.print=25000)
Printing is set to 25000 lines now.

RStudio preview version - Version 0.99.235 has "infinite scroll", so you can view all the data.

utils::View(df) will print everything also in Rstudio (Though this is not using the native Rstudio viewer, we will have to wait for the next version of Rstudio for that)

I don't think it's possible to view more than 1000 rows at a time. However, if your goal is to view data beyond the 1000th row, you can subset your dataset, as follows:
View(df[2000:3000,]) # will show rows 2000-3000
View(df[5000:6000,]) # will show rows 5000-6000

options(max.print=25000)
print.data.frame(<name_of_df>)

Related

How to increase amount of output retained by R console

I'm struggling with how much output is retained in RStudio's console. An MWE would be:
for(i in 1:2000){print(i)}
Of the 2,000 printed iterations, only 1,000 lines are retained in the RStudio console. In other words, scrolling up all the way to the top of the RStudio console, the output is truncated at a printed i of 1001.
To emphasize: these are separate instances of printing to the console, so this has nothing to do with the "max.print" option (which we set to options(max.print=100000) anyway). This is solely about the number of lines retained by RStudio's console, or put differently, the absolute "height" of the console.
This is not an issue when running R through a terminal.
Is someone aware of an RStudio option to increase the amount of lines retained in its console? The RStudio options "Limit output line length" and "Limit visible console output" in Tools > Global Options > Console do not influence this behavior.
Thanks and best,
Chris
you can use rstudioapi::writeRStudioPreference("console_max_lines", <<Number of Lines>>).
<<Number of Lines>> needs to be and Integer so 2000L not 2000.
Then restart RStudio and it will be updated. Be cautious though, this can slow down RStudio a lot for large values.

How Do I View All Output in Rstudio Console When the Output is Large

Take for instance,
rnorm(9999999)
produces a very large output in the console that even if I scroll up to the last limit, I can not see all output.
I prefer solution(s) that will not require me to save the output.
Do
oo <- options(max.print=2e+06) ## set and store defaults
options(oo) ## restore defaults
for two million rows to display (9999999 / 5).
In addition consider the lines cut-off. In RGui it may be configured using [Edit] > [GUI preferences] (see image below).
There are similar options for RStudio, consult this answer for more information.

How to stop jupyter r displaying too many rows?

I used "table" and accidentally run 100000 rows in r Jupiter notebook. Now when I open that file, it is stuck. And I cannot run any command in that file. What can I do to solve this problem?
Use head in order to view the first couple of rows of your table
head(table(df))
Oh, I waited for 30 minutes and then click kernel-->restart and clear output and waited for another 30 minutes.
Just have enough patience, I guess.

R studio List and Dataframes auto name completion not working anymore

Suddenly R Studio stopped auto completing my list and data frame contents when entering mylist$ then pressing Tab. The result message I get is
No matches
I tried that on very simple lists or data frames like:
simpledataset <- data.frame(a=rep(0,100),b=rep(1,100))
However, when I load the dataset Mtcars, it correctly shows the column names.
I reset %localappdata%\RStudio-Desktop by renaming it, but didn't change anything.
Any idea of what could be the cause of that?
This sounds like a bug in the autocompletion system that is occasionally triggered when certain packages are loaded, or the byte-compiler optimization setting is increased. You might try checking a few things:
What is the value of compiler::getCompilerOption("optimize")? Autocompletion is known to fail when this value is equal to 3 in the current RStudio release (v0.99.896). You can try running compiler::setCompilerOptions(optimize = 2) to resolve this.
What packages do you have loaded? You can try loading packages one-by-one to see which affects RStudio's ability to provide autocompletions.
Finally, there should be a fix for this in the preview version of RStudio -- you can try it out at https://www.rstudio.com/products/rstudio/download/preview/.
Go to Tools>Global Options... and set autocomplete there.

R View() does not display all columns of data frame

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?
(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:
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:
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).
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.
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
Try fix(). It loads all your columns and rows. The only problem is that it might take long to load large data frames.
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].

Resources