I would like to see the current working directory in the prompt of my R console. When using options(prompt=paste(getwd(),">> "))
the working directory at the start of the session is shown. But it never gets updated when I change the working directory during that session:
/home/sieste >> setwd("newdir")
/home/sieste >> cat("damn!\n")
What I do at the moment is to redefine the setwd
function in my .Rprofile
setwd <- function(...) {
base::setwd(...)
options(prompt=paste(getwd(),">> "))
}
Now the prompt gets updated correctly whenever I call setwd
. My question is: Is there a more elegant way of updating the prompt dynamically, independent of which function I call and without having to redefine base functions?