Making R installation self-contained/user-independent

后端 未结 4 2029
野趣味
野趣味 2021-01-03 17:14

I\'m trying to get R to ignore c:\\users\\name\\documents and be completely self-contained/portable

Here\'s my directory structure:

.../R/R-2.1.2.2/.         


        
相关标签:
4条回答
  • 2021-01-03 17:51

    In my experience, creating a file named Renviron.site did not work on all my Windows machines, whereas naming the same file .Renviron instead did work everywhere. Not sure why. So if you're having difficulty with the above suggestions, then try .Renviron for a name.

    Please do not hesitate to critically comment about my suggestion, because while I am describing what has worked for me, it may have difficulties I am not aware of.

    In my experience, the following has worked:

    Both Windows and Linux Platform:

    Setting R paths

    Find out the default paths: .libPaths()

    Set the path temporarily (in a R script)

    .libPaths( "F:/Rlib" )
    

    where F could be the letter associated with, say, a USB drive.

    Query paths (both Windows and Linux):

    Sys.getenv('R_LIBS_USER')
    Sys.getenv('R_LIBS')
    Sys.getenv('R_USER')
    Sys.getenv('R_DOC_DIR')
    Sys.getenv('HOME')
    

    Try also:

    normalizePath("~")
    

    Try also:

    getwd()
    setwd(dir)
    

    getwd returns an absolute filepath representing the current working directory of the R process

    setwd(dir) is used to set the working directory to dir.

    Windows (Tested on: 7x64)

    Create an environment file named .Renviron place it in the working directory or home directory:

    "C:/Users/username/Documents"
    

    Some users have reported that the .Renviron file needed to be in "c:/users/username/" instead. If you're not sure where to place it, save the desktop history and see where the .Rhistory file is located. Then place your .Renviron file in the same location. To save history savehistory()

    # Windows .Renviron file:
    R_LIBS_USER="C:/R/library"
    R_USER="C:/R"
    R_DOC_DIR="C:/R"
    HOME="C:"
    

    Set global PATH My Computer / Properties / Advanced System Settings / Environment Variables --> user variables --> Path --> Edit c:\R;c:\R\library;

    Linux (Tested on kUbuntu 12.10)

    Create an environment file named Renviron.site place it in:

    /etc/R/
    

    Query the paths to check that your system is reading the Renviron.site file.

    # Linux Renviron.site file:
    R_LIBS_USER="~/R/library"
    R_USER="~/R"
    R_DOC_DIR="~/R" 
    #HOME="/home" # may not be needed
    

    Remark: afaik the file is read from bottom to top, so HOME is defined at the bottom. In my setup ~ is correctly assigned to /home/ so I omit that last line anyway.

    If you use RStudio, you may also want to add an rsession.conf file in the RStudio program directory. The following has worked for me:

    # Windows 7:
    r-libs-user="C:/R/library"
    # Kubuntu 12:
    # r-libs-user=~/R/%p-library/%v
    
    0 讨论(0)
  • 2021-01-03 17:52

    I used the Rprofile.site file in [your R installation path]\etc and added the following lines to make C:/R/library my default library location each time R is launched:

    # set a site library
     .Library.site <- file.path("C:/R/library")
     .libPaths(.Library.site)
    

    I tried the other answers here but none of them worked with R 2.13.1 on Windows 7 64.

    0 讨论(0)
  • 2021-01-03 17:52

    adding this does the trick:

    .Library.site = file.path( R.home() , ".." , "site-library" )
    .libPaths(.Library.site)
    
    0 讨论(0)
  • 2021-01-03 17:58

    You could create file Renviron.site in [your R installation path]\etc with lines

    HOME="${R_HOME}\..\r_user"
    R_LIBS_SITE="${R_HOME}\..\libs_site"
    

    which set second and third of your settings. First could be replaced by setwd(Sys.getenv("HOME")).

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