永久修改R语言工作目录

来源:互联网 发布:java 网校 源码 编辑:程序博客网 时间:2024/05/16 08:06

默认情况下R语言工作目录每次启动都需要重新设定,为了省事,我们可以把它用命令方式写入到配置文件中,这样每次启动时可以自动设置。

具体方法:

Setting the working directory in R permanently
1)The getwd() command gives the current working directory for R.
The  setwd(<path>) sets the working directory
2)Locate the Rprofile.site file.
•It should be in C:\Program Files\R\R-<version>\etc\Rprofile.site (onWindows).•
I’m not sure where this is on a Mac
3)Add setwd(<path>) to the end of theRprofile.sitefile
•Open the Rprofile.site file on text editor (notepad)
•Add the line below to the end of the

找到这个文件  Rprofile.sitefile  文件最后增加新行,然后输入

setwd("<the desired working directory>")     //关键是 这一行。

重新打开R就OK

•My Rprofile.sitefilelooks like this:
# Things you might want to change
# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")
# set the default help type
# options(help_type="text")
options(help_type="html")
# set a site library
# .Library.site <-file.path(chartr("\\", "/", R.home()),"site-library")
# set a CRAN mirror
# local({r <-getOption("repos")
# r["CRAN"] <-"http://my.local.cran"# options(repos=r)})
setwd("C:\\Programming\\R\\Data\\RegressionClassData")
•NOTICE THE EXTRA EMPTY LINE AFTER THE setwd() COMMAND.
•Save and close this file
•Restart the R GUI
•Typing getwd() on the command line shouldnowreturn the path that wasset in the previous steps.


原创粉丝点击