Chang Yao Liu
Chang Yao Liu

Reputation: 49

How to clear R command history in RStudio?

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?

Upvotes: 3

Views: 13608

Answers (1)

Anshuman Kirty
Anshuman Kirty

Reputation: 166

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

Upvotes: 3

Related Questions