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
:)
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.
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).
You can restart R by clicking on Session -> Restart R (top menu).
In R, press the “Ctrl” + “L” keys simultaneously. The screen will now be refreshed and the console should be cleared.
If you're in RStudio: command/ctrl + shift + F10
You can also use
.rs.restartR()
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.
I found that .rs.restartR() works similar to pressing ctrl+shift+F10. but dose not unload the packages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With