How to create .Renviron file?

后端 未结 4 1672
一生所求
一生所求 2020-12-16 14:15

I need to use my user defined folder where I stored my packages. I have referred the link given below.

R libraries installation

I have applied the same but i

相关标签:
4条回答
  • 2020-12-16 15:01

    It may be worth adding that package usethis now offers a series of function facilitating easy editing and opening of R startup files. Family of edit_* functions can be used to conveniently edit desired startup and configuration files.

    # Edit .R/Makevars
    usethis::edit_r_makevars()
    
    0 讨论(0)
  • 2020-12-16 15:04

    On Mac The Renviron file is located in

    /Library/Frameworks/R.framework/Versions/Current/Resources/etc/
    

    Creating a .Renviron file in the User's home directory will not help.

    0 讨论(0)
  • 2020-12-16 15:10

    Look at help(Startup) which has an example at the end:

     ## Example ~/.Renviron on Unix
     R_LIBS=~/R/library
     PAGER=/usr/local/bin/less
    
     ## Example .Renviron on Windows
     R_LIBS=C:/R/library
     MY_TCLTK="c:/Program Files/Tcl/bin"
    
     ## Example of setting R_DEFAULT_PACKAGES (from R CMD check)
     R_DEFAULT_PACKAGES='utils,grDevices,graphics,stats'
     # this loads the packages in the order given, so they appear on
     # the search path in reverse order.
    

    But note the spelling: Renviron with lower case e. Just use a text editor and edit the file. Also note that R has a variant in one of its system folder etc/ below its RHOME:

    edd@bud:~$ R RHOME
    /usr/lib/R
    edd@bud:~$ cat $(R RHOME)/etc/Renviron.site
    ##                                              Emacs please make this -*- R -*-
    ## empty Renviron.site for R on Debian
    ##
    ## Copyright (C) 2008 Dirk Eddelbuettel and GPL'ed
    ##
    ## see help(Startup) for documentation on ~/.Renviron and Renviron.site
    
    # ## Example ~/.Renviron on Unix
    # R_LIBS=~/R/library
    # PAGER=/usr/local/bin/less
    
    # ## Example .Renviron on Windows
    # R_LIBS=C:/R/library
    # MY_TCLTK="c:/Program Files/Tcl/bin"
    
    # ## Example of setting R_DEFAULT_PACKAGES (from R CMD check)
    # R_DEFAULT_PACKAGES='utils,grDevices,graphics,stats'
    # # this loads the packages in the order given, so they appear on
    # # the search path in reverse order.
    edd@bud:~$ 
    

    Hm. Looks like I wrote that for the Debian package and it does always exist. You can still copy it.

    0 讨论(0)
  • 2020-12-16 15:12

    On mac (or linux)

    Open the terminal and type

    touch $HOME/.Renviron
    

    To open the file you just created, navigate through finder to /Users/<your-user-name>/.Renviron, or simply open the terminal and type

    open $HOME/.Renviron
    

    On windows

    Click on start and open powershell. Copy this code into powershell

    Add-Content c:\Users\$env:USERNAME\Documents\.Renviron "TEST_VARIABLE_1=my_username"
    Add-Content c:\Users\$env:USERNAME\Documents\.Renviron "TEST_VARIABLE_2=123"
    

    You'll now have a file called .Renviron located in the Documents folder. Close and reopen RStudio. Then run Sys.getenv('TEST_VARIABLE_1') to access the variable in R (obviously that works for any other environment variables you set as well).

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