Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear R command history in RStudio?

Tags:

r

I want to completely clear my R command history in RStudio. I'm talking about when I press the up and down arrow keys, not just clearing the console by clicking the broom.

I tried deleting the .Rhistory file in my working directory and restarting RStudio but the file keeps restoring itself. How do I completely get rid of it?

like image 751
Chang Yao Liu Avatar asked Nov 03 '25 02:11

Chang Yao Liu


1 Answers

To clear the workspace environment use:

rm(list = ls())

To clear history of commands typed use:

clearhistory <- function() {
  write("", file=".blank")
  loadhistory(".blank")
  unlink(".blank")
}
clearhistory()

Reference:
This discussion might be helpful: Command or keyboard shortcut to clear command history in RStudio

like image 94
Anshuman Kirty Avatar answered Nov 04 '25 19:11

Anshuman Kirty