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