Calling R from a GAMA model
The RJava extension connects GAML to R through the rJava package and JRI. It is now listed in the community organization's archived gama.plugin.legacy repository, which keeps legacy plugins for reference. Compatibility with GAMA 2026-11 is not established here; check whether a compatible build is available before installing the extension. This page describes the integration provided by the legacy source, not a guarantee that it works with the current release. See the legacy plugin repository.
Requirements and configuration​
You need an R installation, the rJava package installed in that R environment, and the RJava extension installed in GAMA. In R, install and check the package with:
install.packages("rJava")
library(rJava)
Before starting GAMA, configure the environment variable R_HOME to point to the R installation. Add a Java VM argument -Djava.library.path=<JRI-directory> to the GAMA launch configuration, where <JRI-directory> is the directory containing the native JRI library installed with rJava. The extension checks that R_HOME is set and that Java's library path includes the JRI directory. Restart GAMA after changing the environment or VM arguments.
For general installation steps, see Installing Plugins. The community plugin catalog currently classifies RJava as a legacy plugin; availability in an update site does not by itself confirm compatibility with a particular GAMA release.
Start R and evaluate expressions​
Declare the RSkill on the agent that will use R, then call startR before evaluating commands. R_eval evaluates R code and converts supported results back to GAMA values. Calls share the same R session, so variables created by one call remain available to later calls.
model r_example
global skills: [RSkill] {
init {
do startR;
write R_eval("x <- 1");
write R_eval("x + 1");
}
}
experiment main mode: gui {}
The extension also provides R_eval_script to source a script file, to_R_data to convert GAMA values for R, and to_R_dataframe to convert a species population to an R data frame. See the extension's example models for complete examples.
This example covers use in a GUI experiment. It does not document headless execution.