Remove a library from .libPaths() permanently without Rprofile.site

后端 未结 5 1165
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 18:57

How can I permanently remove a library in R?

.libPaths()
[1] \"\\\\\\\\per-homedrive1.corp.riotinto.org/homedrive$/Tommy.O\'Dell/R/win-library/2.15\"
[2] \         


        
相关标签:
5条回答
  • 2020-12-02 19:05

    Just set the environment variable R_LIBS in Windows to something like

    R_LIBS=C:/Program Files/R/R-2.15.2/library
    

    Restart R.

    0 讨论(0)
  • 2020-12-02 19:10

    This is bit late response to the question, but might be useful for others. I order to set up my own path (and remove one of the original ones) I have:

    • used .libPaths() inside R to check current library paths;
    • identified which paths to keep. In my case, it kept R's original library but removed link to my documents.
    • found R-Home path using R.home() or Sys.getenv("R_HOME");
      • R-Home\R-3.2.2\etc\Rprofile.site is read every time R kernel starts. Therefore, any modification will be persistent to every run of R.
    • Edited Rprofile.site by adding the following,

    .libPaths(.libPaths()[2]) .libPaths("d:/tmp/R/win-library/3.2")

    How it works?

    • First line remove all but one path (second from the original list), the second line adds an additional path. We end up with two paths.
    • note that I use Unix path notation despite using windows. R always use Unix notation, regardless of operating system
    • restarted R (using Ctr+Shift+F10)

    This will work every time now.

    0 讨论(0)
  • 2020-12-02 19:11

    I have put the Sys.unsetenv("R_LIBS_USER") command in a .Rprofile file in my windows "own documents" folder. Seems to help. My problem was that being in an active directory environment made R upstart and package loading incredibly slow when connected via vpn.

    0 讨论(0)
  • 2020-12-02 19:22

    If you want to do this at RProfile file (@library/base/R/), you can search the lines where R_LIBS_* environment variables are set (for e.g. Sys.setenv(R_LIBS_SITE=....) and Sys.setenv(R_LIBS_USER=.....)) You can also search the code .libPaths(), which sets the library tree. So you can achieve your goal by a combination of commenting, unsetting and setting the R_LIBS variables before the .libPaths() call as you wish. For e.g. Something like:

    Sys.unsetenv("R_LIBS")
    Sys.unsetenv("R_LIBS_USER")
    Sys.setenv(R_LIBS_SITE = "D:/R/libs/site")
    Sys.setenv(R_LIBS_USER = "D:/R/libs/user")
    Sys.setenv(R_LIBS = "D:/R/libs")
    
    0 讨论(0)
  • 2020-12-02 19:26

    Use this function in .Rprofile

    set_lib_paths <- function(lib_vec) {
      lib_vec <- normalizePath(lib_vec, mustWork = TRUE)
      shim_fun <- .libPaths
      shim_env <- new.env(parent = environment(shim_fun))
      shim_env$.Library <- character()
      shim_env$.Library.site <- character()
      environment(shim_fun) <- shim_env
      shim_fun(lib_vec)
    }
    set_lib_paths("~/code/library") # where "~/code/library" is your package directory
    

    Original Source: https://milesmcbain.xyz/hacking-r-library-paths/

    0 讨论(0)
提交回复
热议问题