永久修改R语言工作目录

默认情况下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.


  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值