Re: RTools and previous Cygwin installation--conflict?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: RTools and previous Cygwin installation--conflict?

R help mailing list-2
I sent a query on this subject over 4 years ago.

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.

That approach, however, fails as of RTools 3.5, since RTools switched from cygwin commands to msys2.
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"

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
function calls a new function

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:

[hidden email] mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.