[R] RTools and previous Cygwin installation--conflict?

Brent yhbrent @ending from y@hoo@com
Tue Oct 16 00:40:20 CEST 2018


I sent a query on this subject over 4 years ago.
    https://www.mail-archive.com/r-help@r-project.org/msg212269.html

I used to use Duncan Murdoch's suggestion to install only cygwin 32 bit and then put RTools first in my Windows path, so that its versions of cygwin commands would get pick up first.
    https://www.mail-archive.com/r-help@r-project.org/msg212281.html

That approach, however, fails as of RTools 3.5, since RTools switched from cygwin commands to msys2.
    https://cran.r-project.org/bin/windows/Rtools/Rtools.txt
The mysys commands are incompatible with cygwin; you will get strange errors in cygwin if it tries to use msys2 commands.

This forced me to reconsider this problem, and I think that I came up with a much better approach that I want to share for the benefit of others.

Gabor Grothendieck had already suggested using a DOS batch file to temporarily alter the PATH env var "to R and to Rtools only when R is being used in order to avoid conflicts"
    https://www.mail-archive.com/r-help@r-project.org/msg212275.html

My solution is similar, except that instead of doing this in a DOS batch file, I do it as the first action within R itself.

In particular, I edited R .Rprofile file so that its
    .First
function calls a new function
    add_RTools_toPATH()

That function is:
    # Modifies the PATH environmental variable to have the path to the RTools bin directory as its first element.
    # This change only affects the current R session (and any processes it spawns?); it does not permanently alter the Windows system env var.
    add_RTools_toPATH = function() {
        # get the existing PATH env var's value:
        pathEnvVar = Sys.getenv("PATH")
        
        # check that it does not already have an Rtools element:
        if (grepl("Rtools", pathEnvVar, fixed = TRUE)) {
            stop("Your existing Windows PATH env var (printed below) already contains the substring \"Rtools\", which is unexpected:", "\n", pathEnvVar)
        }
        
        # add C:\Rtools\bin to the front of PATH:
        pathNew = paste( "C:\\Rtools\\bin", Sys.getenv("PATH"), sep = ";" )
        Sys.setenv(PATH = pathNew)
    }


This new solution allows me to use whatever version of cygwin I want (e.g. 64 bit) with no worries about collision as before.  It also lets me exactly control the PATH for my R sessions.

Here are some background links if you do not fully understand the above:
    https://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html
    https://stat.ethz.ch/R-manual/R-devel/library/base/html/Sys.setenv.html
    https://stackoverflow.com/questions/24622725/how-to-set-path-on-windows-through-r-shell-command



More information about the R-help mailing list