How to show working directory in R prompt?

This question already has an answer here:

  • Display a time clock in the R command line 5 answers

  • Because prompt option is really just a string, without any special directives evaluated inside (unlike shell prompt), you have to change it if you change working directory to get current working directory inside.

    The solution you use seems the best to me. A bit hacky, but any solution will be as you want to implement something quite fundamental that is not supported by R itself.

    Moreover, you don't have to fear functions executing base::setwd under the hood, which would get your prompt out of sync with real working directory. That does not happen in practice. As Thomas pointed out in the comments, probably no base functions (other than source ) call setwd . The only functions that do are related to package building and installation. And I noticed that even in source and usually in the other functions, setwd is used like owd <- setwd(dir); on.exit(setwd(owd)) owd <- setwd(dir); on.exit(setwd(owd)) , so that the working directory is set back to original when the function finishes.

    链接地址: http://www.djcxy.com/p/22108.html

    上一篇: 文本输入框不接受来自Angular UI Bootstrap的模态输入

    下一篇: 如何在R提示符中显示工作目录?