Rstudio project启动时如果在project根目录下有.Rprofile文件,就会执行。因此可以把这个需要运行的函数放到.Rprofile文件中,再把.Rprofile放到project目录下。
一个.Rprofile的例子:
# 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)})
.First <- function(){
#Sys.setenv("R_ZIPCMD" = "d:/Rtools/bin/zip.exe")
options(defaultPackages=c(getOption("defaultPackages"),"tidyverse","cowplot","stringr","rio","strF","pacman"))
cat("014")
#source('R/20180130strF_functions.R')
wens()
}
# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
# if (interactive())
# fortunes::fortune()
可以把这个函数放在.First <- function()后面的大括号中。例如cat("014")是清屏作用。
如果不用project也可以设定。
见
https://zhuanlan.zhihu.com/p/56304655
参考:
Using Projectssupport.rstudio.com