Keyboard shortcut for cleaning global environment

I would like to set a keyboard shortcut for clening global environment in RStudio, but without that confirmation about hidden variables.
Just a ks that is cleaning everything when I run it. Ho do I do it ?

There is ctrl+shift+F10 that restarts R starting a fresh session. It will delete all variables in the environment, but also all plots etc.

You can also find it in the menu Session>Restart R.

Hi, this is not what I want, it takes too long. I juzt would like to clean GE with single keyboard shortcut.

I don't know of another keyboard shortcut (as restarting the session offers a better "blank state"), but it shouldn't be too hard to write it as an add-in.

The only option in base RStudio to clear the GE (aside from the broom) would be to type the following into RStudio's console;

rm(list = ls())

How do I do it to assign a keyboard shortcut to this command ? Is it possible at all ?

It is not possible within RStudio. Any macro/shortcut would have to be facilitated through your OS or a third-party application.

Alex provided a link, Rstudio Add-ins can be assigned shortcuts, and your r code to clear objects could be surfaced by that route

Restarting would really be the best. If this is taking too long you are likely restoring your previous .RData workspace on startup, which is not a good idea. If that's the case just change the Workspace options from the Global Options menu.


On my machine, Restarting the R session takes about 10 seconds (I don't restore .RData, but I source some files in my .First() function which takes a few of those seconds), while rm(list = ls()) is instantaneous.
The biggest difference is that rm(list=ls()) clears only the Global Environment (including functions): it leaves any additional libraries and any variables in environments other than the Global Environment loaded and unchanged.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.