用Rprofile文件配置打开时R的设置

R中经常会使用一些命令,而且需要重复输入,非常麻烦。如果能够一打开R就直接使用会方便很多。

通过配置一个.Rprofile文件,可以达到我们的目的。

注:本文仅适用于Mac

# 创建一个.Rprofile file
emacs ~/.Rprofile
# Edit the .Rprofile file
# General options
options(tab.width = 4)
options(width = 130)
options(graphics.record=TRUE)

.First <- function(){
# To load bioconductor ( I have typed this command for hundreds of times )
 source("http://bioconductor.org/biocLite.R")
# To load some functions that is convenient to you
 source("~/.MyRfunctions.R")
 cat("\nWelcome at", date(), "\n")
}

.Last <- function(){
 cat("\nGoodbye at ", date(), "\n")
 

这个.MyRfunctions.R 可以写一些自己方便的函数,比如:

# Function: a brief function to read data from clippboard 
read.clippboard    = function() {
        return(read.table(pipe("pbpaste")))
}

当然,还可以加入很多其他的东西。。。

这样,当我打开R时,可以直接输入bioconductor的命令 biocLite("package")!

当我想要阅读剪贴板的data,直接打read.clippboard()即可!

 

Reference: 

http://www.statmethods.net/interface/customizing.html

posted on 2015-01-27 09:06  Forever_YCC  阅读(3518)  评论(0编辑  收藏  举报

导航