Overview

The gstlearn R package is a cross-platform R package wrapping the gstlearn C++ Library. It offers to R users all famous Geostatistical methodologies developed and/or invented by the Geostatistic Team of the Geosciences Research Center!

All gstlearn outputs can be ploted using plot generic function which relies on ggplot package.

References

The gstlearn R package is a R wrapper of the gstlearn C++ Library. It's the successor of the RGeostats R package.

This package contains a modified copy of findR.cmake script (see LICENSE.root in root folder).q

The gstlearn R package is a derivative work based on the swigex0 project: https://github.com/fabien-ors/swigex0

How to cite

When using the gstlearn R Package, please, use this to cite us in any publication or results for which gstlearn has been used:

--------------------------------------------------
gstlearn
Geostatistics and Machine Learning toolbox
Copyright © MINES Paris - PSL University
Free download from https://gstlearn.org
--------------------------------------------------

You may be interested in the citation file gstlearn.bib

Installation

For using this R Package you only need R 4.2 (or higher) and execute the following R command:

install.packages("gstlearn",repos="https://soft.mines-paristech.fr/cran")

Note: With slow Internet connection, you may need to increase the default timeout (60s) (gstlearn package is around 17Mo!)

options(timeout=1000)

Usage

We refer the reader to this course page for an introduction and important information about R gstlearn.

# Load gstlearn package
library(gstlearn)
library(ggplot2)
# Grid size
nx = 60
ny = 30
mygrid = DbGrid_create(c(nx,ny), c(1,1))
# Add a gaussian random field
var = rnorm(nx * ny)
mygrid$addColumns(var, "var1", ELoc_Z())
# Display the field
ggplot() + plot.grid(mygrid) + plot.decoration(title="Gaussian random field")

Some tutorials (RMarkdown) are provided in the demo directory here.

Some tests (R Scripts) are available in the tests directory of the gstlearn github repository.

Changelog

Please, look at CHANGES file.

Developments

Requirements

For building the gstlearn R package, the requirements for building gstlearn C++ library must be installed beforehand. Then, the following additional tools must be also available:

If you modified your system (or if you installed a new version or RTools), you must reinstall the requirements from scratch following next instructions. You must delete 'gstlearn' and 'swig' existing source folders (if so).

Note :

Linux (Ubuntu)

  1. Install gstlearn C++ library requirements for Linux here

  2. Remove any previous installation of SWIG (if any)

  3. Then, execute the following commands:

sudo apt install r-base
sudo apt install bison
sudo apt install pcre2-devel # Ubuntu 18
sudo apt install libpcre2-dev # Ubuntu 20
  1. In a directory of your choice, get the source of SWIG 4.2.0 [customized] by executing following commands (in the same shell):
git clone https://github.com/fabien-ors/swig.git
cd swig

Next time (if a new version of SWIG 4.2.0 [customized] is delivered), you will only need to pull the repository

cd swig
git pull
  1. Then compile and install SWIG 4.2.0 [customized] :
cmake -Bbuild
cd build
make
sudo make install
  1. Finally, install the R optional packages from an R command prompt:
install.packages(c("ggplot2", "ggpubr", "knitr", "callr"), repos="https://cloud.r-project.org")

MacOS

  1. Install gstlearn C++ library requirements for MacOS here

  2. Remove any previous installation of SWIG (if any)

  3. Then, execute the following commands (Not tested):

brew install r
brew install bison
brew install pcre2-devel
  1. In a directory of your choice, get the source of SWIG 4.2.0 [customized] by executing following commands (in the same shell):
git clone https://github.com/fabien-ors/swig.git
cd swig

Next time (if a new version of SWIG 4.2.0 [customized] is delivered), you will only need to pull the repository

cd swig
git pull
  1. Then compile and install SWIG 4.2.0 [customized] :
cmake -Bbuild
cd build
make
sudo make install
  1. Finally, install the R optional packages from an R command prompt:
install.packages(c("ggplot2", "ggpubr", "knitr", "callr"), repos="https://cloud.r-project.org")

Note :

Windows

  1. Install gstlearn C++ library requirements for Windows (RTools) here

  2. Remove any previous installation of SWIG (if any)

  3. Launch mingw64.exe in RTools installation directory (i.e.: C:\rtools42) and pin the icon to the task bar

pacman -Sy bison
pacman -Sy mingw-w64-x86_64-pcre2
  1. In a directory of your choice, get the source of SWIG 4.2.0 [customized] by executing following commands (in the same shell):
git clone https://github.com/fabien-ors/swig.git
cd swig

Next time (if a new version of SWIG 4.2.0 [customized] is delivered), you will only need to pull the repository

cd swig
git pull
  1. Then compile and install SWIG 4.2.0 [customized] :
cmake -G "MSYS Makefiles" -Bbuild -DCMAKE_INSTALL_PREFIX:PATH=/mingw64/
cd build
make
make install
  1. Finally, install the R optional packages from an R command prompt:
install.packages(c("ggplot2", "ggpubr", "knitr", "callr"), repos="https://cloud.r-project.org")

Installation from Source

  1. For getting the gstlearn R package sources files, just clone the github repository:
git clone https://github.com/gstlearn/gstlearn.git
cd gstlearn

Next time, you will only need to pull the repository (If you have some local undesirable modifications, you have to revert them and execute the pull, otherwise do not execute git reset):

cd gstlearn
git reset --hard
git pull
  1. Then, these instructions will compile and install the gstlearn R package in your usual R libraries directory:
cmake -Bbuild -S. -DBUILD_R=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --target r_install

or even faster:

make r_install

Execute Non-regression Tests

The check* targets bring some required runtime customization, so do not use the standard ctest command for triggering the non-regression tests.

To build and launch non-regression R tests, you need to execute the following command:

cmake --build build --target check_r

or even faster:

make check_r

Important Notes

Remove Installed Package

Execute the following command from an R command prompt:

remove.packages("gstlearn")

License

GPL v3 2023 Team gstlearn