gretl   and    GNU R

Gretl (main page here) is a free, user-friendly and sophisticated econometrics package. Its coverage of statistical methods is, however, not as comprehensive as that of GNU R, which is also free, open-source software.

To facilitate inter-operation of the two programs, gretl offers the ability to save the current data set in a format suitable for analysis using R; to launch an R session with the current gretl data set automatically loaded into R's workspace; to embed R scripts within gretl scripts; and, more generally, to have the two programs exchange data and results in a fairly transparent way. The Gretl User's Guide has a chapter devoted to this topic.

To find out more about GNU R, we recommend starting with An Introduction to R. For further information, and to download R, visit cran.r-project.org.

The most efficient interaction with R is achieved by gretl calling into the R shared library (libR.so on Linux, libR.dylib on macOS, or R.dll on MS Windows). This requires that the R library knows where its “home” is. The details of ensuring this point vary by platform, as follows.

MS Windows

By default, the R installer writes the required information into the Windows Registry. It's possible to customize the install such that no registry entry is created: don't do that if you want to use R with gretl.

Linux or similar

R_HOME should be defined in the environment. This should be the parent directory of lib/libR.so. For example, if /usr/lib/R/lib/libR.so exists, /usr/lib/R is the correct value for R_HOME.

macOS

Given a standard installation of R, nothing special should be needed. In a non-standard case you should define R_HOME to point to the parent directory of lib/libR.dylib, similar to the Linux case.

Alternative method

An alternative is to specify the path to the shared library itself, under /Tools/Preferences/General/Programs in gretl. The relevant entry is “Path to R library”. If that setting is correct gretl can take care of putting a suitable value for R_HOME into the environment. On Windows, however, this setting will require updating whenever a new version of R is installed, so relying on the Registry is preferred.