Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling back through the RStudio console

Tags:

r

console

rstudio

This is just a RStudio interface question:

When scrolling back through the console to see my work and outputs I can only scroll back so far. Is there a way to open up the console and scroll back through everything I have done?

Sometimes I want to check results of a very long list, or I forget to write code in the script box instead of the console and want to scroll back to review it.

Cheers,

like image 223
bubbalouie Avatar asked Dec 04 '14 00:12

bubbalouie


2 Answers

In addition to the excellent comments of others, if you have a data.frame called df with 2000 rows and 2 columns, to view all of them, type on the console:

utils::View(df) # opens a new separate window to view all the records.

In order to view just 500:1000 records of the data.frame just do:

utils::View(df[500:1000,]) 
like image 147
lawyeR Avatar answered Oct 10 '22 21:10

lawyeR


To build on jbaums's comment, I personally got really tired of typing .Last.value whenever I wanted to grab a temporary variable (especially when in Matlab its just ans and in Python its _.)

So as a workaround you can bind ans to Last.value to save yourself some time typing: makeActiveBinding("ans", function(){.Last.value}, .GlobalEnv).

As a super-lame example of how this could be super-helpful at times:

> runif(5)  # Oh no! I forgot to assign my function output to a variable!
[1] 0.1905214 0.2175722 0.1140303 0.2645469 0.8298856
> ans  # Oh wait, we're good :)
[1] 0.1905214 0.2175722 0.1140303 0.2645469 0.8298856

To make it a bit more permanent, save that in a file named .Rprofile. If you use Rstudio projects a lot, you can save it to the project working directory and it will load every time you boot up Rstudio. Otherwise you can put that line of code in the Rprofile.site file in your R directory (mine's located in \Program Files\R\R-3.2.0\etc) and R should load it by default, though I'm not 100% sure.

like image 42
Jacob Amos Avatar answered Oct 10 '22 20:10

Jacob Amos