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. Continue reading →
Just to quickly share this great new website where you can search the documentation of all R packages and functions available on CRAN (6688 R packages and 136342 R functions at the moment of writing!). It offers instant or advanced search options in an easy interface, and there is even a package that allows you to use the search functionality from within R. Check it out on http://www.rdocumentation.org/.
A common objective of correlative species distribution model is to be able to project the potential distribution of the target species into a new environmental space. This can be a new geographic space (e.g., invasive species) or projected future conditions.
One should be very careful in interpreting results if extrapolating to areas with conditions that fall outside the range of reference environmental variation. There are several methods to visualize this uncertainty. On this blog I have for example mentioned the multi-environmental similarity tool in Maxent (also implemented in R in amongst others the dismo package and as an addon for GRASS GIS), which allows you to create maps that provides the similarity of each point to a set of reference points (Elith et al. 2010) and thus provide a quick overview of areas with ‘novel’ conditions.
A disadvantage of this and other methods is that they only consider the ranges of the individual predictors, and ignore the correlation structure of the covariates used to build the model. In reality, it is not unlikely that at a given locations values of each univariate factor fall within the original range of values, but the combination of environmental conditions is new. Continue reading →
In R you can use system calls or the spgrass6 package to run GRASS GIS functions. To do this, you need to run R from within GRASS GIS. This is as simple as starting GRASS GIS and subsequently starting R from the command line. See the GRASS-wiki for a more detailed background.
The issue at hand
One of the user-cases is when you want to (1) run a GRASS function on e.g., a raster layer and (2) capture the console output in a R data frame. For example, you can run the following in R:
The Multivariate Environmental Similarity Surfaces (MESS) is an index that represents how similar a point in space is to a reference set of points, with respect to a set of predictor variables (Elith et al 2010). The function was first implemented as part of the Maxent software package, and is also available in the dismo package for R (see also here and here).
The latter works well on small and medium sized data sets. However, they take a long time to run on larger data sets, e.g., when working with 1km² raster grids covering eastern Africa. I therefore wrote a small R script to compute MESS in GRASS GIS. Continue reading →
Read the whole vector layer
It allows you amongst others to easily import vector data layers from GRASS GIS into R using the function readVECT6(). This will import the whole vector layer. But what if you you only need to import the attribute table? Importing the whole vector layer would give unnecessarily overhead and would take (much) longer to import. Continue reading →
Jean-Pierre Rossi introduced a function to calculate the “Multivariate Environmental Similarity Surfaces” in R. Since then, the function has become part of the dismo package, which is a package maintained by Robert J. Hijmans and which offers a whole lot of functions for species distribution modelling.
The function calculates the MESS based on a point layer (the reference points) and a set of raster layers (the environmental data layers). It works great for smaller data sets, but you may run into trouble for very large data sets. So I needed to find a way to run this faster. And… I couldn’t. It is already a pretty neat piece of code, and I could not think of a better way of doing this in R. (I am working on For an alternative to do this in GRASS, but more about that later: see here).