Using Gurobi with R on the Yens

Gurobi R package is installed and available system-wide to use on the Yens. You do not need to install anything into your user R package directory. To use Gurobi software with R, you simply need to load both modules at once when logging into Yens:

$ module load gurobi R

List loaded modules:

$ ml

Currently Loaded Modules:
  1) gurobi/9.5.2   2) rstudio/1.1.463   3) R/4.2.1

Launch interactive R:

$ R

Then you can load the gurobi R package:

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library('gurobi')
Loading required package: slam
>

Troubleshooting

If you forget to load gurobi module, you will see the following error when you try to load it into R:

> library('gurobi')
Loading required package: slam
Error: package or namespace load failed for gurobi in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/software/free/R/R-4.2.1/lib/R/library/gurobi/libs/gurobi.so':
  libgurobi95.so: cannot open shared object file: No such file or directory

To fix, exit R and make sure to load gurobi module first. Then open R again and the gurobi library should load.