R语言自定义启动环境

原文地址:http://blog.sina.com.cn/s/blog_50ccfc410101eigd.html

平时做R开发时,每次启动R环境都会要加载很多package,甚是繁琐。最近学习《R in action》时,介绍了自定义R启动环境的方法。

windows环境下,R启动时会到R_Home\etc目录下找Rprofile.site文件,其中“R_Home”指的是R安装目录,例如c:\R。可以用notepad等文本编辑器打开c:\R\etc\Rprofile.site,进行修改
 
# Things you might want to change
# 下面是常规设置,包括,默认编辑器、制表符宽度等等
# options(papersize="a4")
# options(tab.width=2)
# 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
# 设置CRAN镜像,选一个最近源,这样安装和更新包时就不用手动选取CRAN镜像了
 local({r <- getOption("repos")
       r["CRAN"] <- "http://ftp.ctex.org/mirrors/CRAN/"
       options(repos=r)})
# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
#  if (interactive())
#    fortunes::fortune()
.First <- function(){
# 设置R启动时加载的包
library(TSA)
library(MASS)
# 启动时交互,可自定义
cat("\nWelcome at",date(),"\n")
}
# 退出时交互
.Last <- function(){
cat("\nGoodnye at",date(),"\n")
}
 
.First()函数中除了加载常用package之外,还可以加载保存自己编写的常用函数的源代码文件
.Last()函数可以执行推出时清理工作,如保存命令历史记录、保存数据输出和数据文件等等
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值