How to Change .libPaths() permanently in R?

前端 未结 4 1434
無奈伤痛
無奈伤痛 2020-12-01 07:52

Whenever I change the library path order using the .libPaths() function, it reverts back to the default if I restart R. How can I change this permanently? I am

4条回答
  •  遥遥无期
    2020-12-01 08:17

    find the Rprofile file (no dot) in R installation folder

    find -name Rprofile
    
    #Getting something like:
    #lib/R/library/base/R/Rprofile
    

    Open the file and search for:

    invisible(.libPaths(c(unlist(strsplit(Sys.getenv("R_LIBS"), ":")),
                          unlist(strsplit(Sys.getenv("R_LIBS_USER"), ":") )
                          )))
    

    comment other paths and add your desired path

    invisible(.libPaths(c(#unlist(strsplit(Sys.getenv("R_LIBS"), ":")),
                          #unlist(strsplit(Sys.getenv("R_LIBS_USER"), ":") )
                          "/home/users/username/R/4.0.1/lib/R/library" # desired path
                          )))
    

    This can be useful also: (for .bashrc file)

    export R_LIBS='/home/users/username/R/4.0.1/lib/R/library'
    export R_LIBS_USER='/home/users/username/R/4.0.1/lib/R/library'
    

提交回复
热议问题