Resurrecting an old question because neither of the above solutions were what I was after. An alternative that doesn't require external interfaces is to use system commands as rawr suggested. This can be done with something like the following. First, create a java class in AnyLogic with the following code (modified from this guide)
import java.io.*;
public class SystemUtil {
public static Process executeCommands(String commands, String directory, String errorFile) {
Process process = null;
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
ProcessBuilder pb;
if(isWindows) {
pb = new ProcessBuilder("cmd.exe","/c",commands);
} else {
pb = new ProcessBuilder("/bin/sh","-c",commands);
}
pb.directory(new File(directory)); //Set current directory
pb.redirectError(new File(errorFile)); //Log errors in specified log file.
try {
process = pb.start();
} catch (IOException e) {
e.printStackTrace();
}
return process;
}
}
With that done, you should be able to invoke any system command you want, including Rscript, using the newly defined class. As a toy example, if you place this code into a button you'll create a CSV file containing a 3x3 diagonal matrix. Replace the command with the appropriate Rscript call for your script.
String command = "Rscript -e write.csv(diag(3),file='out.csv')";
String dir = System.getProperty("user.dir");
String log = String.format("%s/log.txt",dir);
SystemUtil.executeCommands(command,dir,log);