Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quit and restart a clean R session from within R?

Tags:

alias

r

Is there a way I can make an alias, within R, that will execute q() and then restart a clean R session?

And yes, I am too lazy to type q() and then the letter R :)

like image 692
justin Avatar asked Jun 10 '11 23:06

justin


People also ask

How do I run a clean Session in R?

You can do both by restarting your R session in RStudio with the keyboard shortcut Ctrl+Shift+F10 which will totally clear your global environment of both objects and loaded packages.

How do I restart an R Session in RStudio?

If you use RStudio, use the menu item Session > Restart R or the associated keyboard shortcut Ctrl+Shift+F10 (Windows and Linux) or Command+Shift+F10 (Mac OS).

How do I start over in R?

You can restart R by clicking on Session -> Restart R (top menu).

How do I reset my R program?

In R, press the “Ctrl” + “L” keys simultaneously. The screen will now be refreshed and the console should be cleared.


Video Answer


3 Answers

If you're in RStudio: command/ctrl + shift + F10

You can also use

.rs.restartR()
like image 112
mgoldwasser Avatar answered Oct 20 '22 16:10

mgoldwasser


Depending on how you start R try placing one of these lines into your .Rprofile file:

makeActiveBinding("refresh", function() { shell("Rgui"); q("no") }, .GlobalEnv)

makeActiveBinding("refresh", function() { system("R"); q("no") }, .GlobalEnv)

Then entering this into the R console:

refresh

will shut down the current session and start up a new one.

like image 61
G. Grothendieck Avatar answered Oct 20 '22 15:10

G. Grothendieck


I found that .rs.restartR() works similar to pressing ctrl+shift+F10. but dose not unload the packages

like image 16
Adam Lee Perelman Avatar answered Oct 20 '22 15:10

Adam Lee Perelman