美文网首页
R语言 小技巧

R语言 小技巧

作者: 别花春水 | 来源:发表于2020-02-14 17:13 被阅读0次
    • ?Startup

    **可以编辑每次刚打开Rstudio时显示在console里的提示语/欢迎语,或在每次打开/关闭任意R文件前先运行一段R语句。
    找到\Miniconda3\Lib\R\etc\Rprofile.site这个文件,在里面作修改即可。
    其他option可以查看?startup
    《R in action》里有简略解释,搜索Appendix B Customizing the startup environment即可。

    # 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)})
    
    # Give a fortune cookie, but only to interactive sessions
    # (This would need the fortunes package to be installed.)
    #  if (interactive()) 
    #    fortunes::fortune()
    
    .First <- function(){
      # 加载程序包跟平常一样用library或require
      
      #你可以将自定义函数的代码脚本保存到"D:/myfunctions.R"文件里
      #如果有的话,加载函数用source函数
      myfilepath <- "F:/ProgramFiles/Miniconda3/Lib/R/etc/myfunction.R"
      source(myfilepath) 
      # 启动提示语,可有可无
      Sys.setlocale("LC_TIME", "English") #将sys.time时间变成英文显示
      cat("Today is",format(Sys.time(), "%Y-%b-%d %A %H:%M:%S"),"\n")
      cat("myfunction.R is loaded. sourced from",myfilepath,"\n") 
        rfpath<-"F:\ProgramFiles\Miniconda3\Lib\R\etc\Rprofile.site"
      cat("To edit Starup text, search",rfpath,"\n")  
    }
    
    Starup
    • Sys.setlocale("LC_TIME", "English") 可以将sys.time()时间变成英文显示。

    相关文章

      网友评论

          本文标题:R语言 小技巧

          本文链接:https://www.haomeiwen.com/subject/bpkjfhtx.html