Since I have switch from Windows to Linux, many years ago, things have started to look a lot brighter for those wanting to use GRASS on Windows. I won’t switch back to Windows any time soon, but I recently had to install WinGRASS for somebody else. And it was a whole lot easier than I had feared (or even hoped).
But there is one thing I couldn’t immediately figure out; how to run R from within GRASS. I should add that I installed GRASS using the OSGEO4W installer. When installing GRASS using the stand alone installer, access to R from the GRASS command line should work out-of-the-box (see comment from Helmut in the comment section below).
After a bit of trial and error, I came up with the steps below. It involves editing a file to tell GRASS where to look for executables. In the example below I am adding the path to the R and rstudio executables to this file. Having done that, I can now type R.exe or rstudio.exe on the GRASS command line to open these programs.
Install GRASS GIS using OSGEO4W
Note that I have installed GRASS GIS grass-7.0.0beta3. If you install another version, just substitute the version number with the one you installed in the commands below.
Step 1: Assuming you installed the osgeo4w in the default location (C:\OSGeo4W), go to C:\OSGeo4W\apps\grass\grass-7.0.0beta3\etc
Step 2: Open the env.bat file in your favourite text editor, and look for the line that starts with set PATH (probably the last line). This line tells GRASS where to look for executable files.
Step 3: Ad the following two lines above that line (the paths may differ on your computer):
set RCRAN=C:\Program Files\R\R-3.0.1\bin set RSTUDIO=C:\Program Files\RStudio\bin
Step 4: Change the line that sets the PATH by adding the references to R and RStudio.
Now start GRASS and type on the command line R.exe or rstudio.exe to open R or RStudio respectively (see the GRASS wiki about using R and GRASS).
GRASS installed with the stand alone installer
As mentioned above, if you have installed GRASS GIS with the stand alone installer, things
may should work out-of-the-box (see comment from Helmut below). If it for some reason doesn’t (it didn’t for me), you can always edit the grass70.bat file in the c:\Program Files\grass-7.0beta3 folder, using the same steps as above.