########################################################
# Installation instructions for the Xpress R interface #
########################################################

This package provides the interface to call
the FICO Xpress Optimizer natively within the R programming language
to solve linear, integer, and quadratic optimization problems.

Find below the installation instructions for all supported platforms.

=================
Microsoft Windows
=================

Windows users will find a ZIP archive in their Xpress installation directory.
If Xpress was installed in the standard location,
the archive is located under

    C:\xpressmp\R\xpress.zip

Open an R Terminal or Rstudio, and type (make sure to pick the ZIP archive, not the tar.gz)

    install.packages("C:\\xpressmp\\R\\xpress.zip", repos = NULL, type = "win.binary")

You can now import the xpress library into your R session and try to create a problem.

    library(xpress)
    p <- createprob()
    print(p)


The above will only work if your version of R is compatible with the version for
which the binary was built. If you have an incompatible version then you can
install the xpress package from source.
To do so you first need to installs rtools for your version
of R, which can be obtained from CRAN.

Then open an R Terminal or Rstudio, and type

    install.packages("C:\\xpressmp\\R\\xpress.tar.gz", repos = NULL, type = "source", INSTALL_opts = c("--no-multiarch"))

Note that here you specify the tarball (the .tar.gz file), not the ZIP archive.

=============
Linux and Mac
=============

Linux and Mac users will find a TAR archive archive in their Xpress installation directory.
If Xpress was installed in the standard location,
the archive is usually located under

    /opt/xpressmp/R/xpress.tar.gz   (Linux)
    /Applications/FICO Xpress/xpressmp/R/xpress.tar.gz (Mac)

It is extremely important that you launch R with the correct environment variables set, see Troubleshooting below.

Open an R Terminal or Rstudio, and type

    install.packages("/opt/xpressmp/R/xpress.tar.gz") # (Linux)
    install.packages("/Applications/FICO Xpress/xpressmp/R/xpress.tar.gz") # (Mac)

Like on Windows, you can now import the xpress library into your R session and try to create a problem.

    library(xpress)
    p <- createprob()
    print(p)

Troubleshooting:
================

## Installation from Source under Windows

If you build the xpress package from the source tarball xpress.tar.gz,
the linking step may fail because of undefined references to library
functions. Please make sure to specify the installation option
"--no-multiarch" when calling `install.packages` to force
a 64bit build:

    install.packages("C:\\xpressmp\\R\\xpress.tar.gz", repos = NULL, type = "source", INSTALL_opts = c("--no-multiarch"))

## Missing environment variables

Under Linux, the following environment variables must be set to correctly locate the Xpress installation.
Assuming the standard installation path, it should be sufficient to execute

    source /opt/xpressmp/bin/xpvars.sh

*before* you start R or rstudio.

You can also specify the locations of your installation manually by setting

    export XPRESSDIR=/opt/xpressmp/
    export LD_LIBRARY_PATH=${XPRESSDIR}/lib:${LD_LIBRARY_PATH}
    export XPAUTH_PATH=/home/${USER}/xpauth.xpr              # or the location where your license file is located

In order to specify a permanent launch configuration
for RStudio, you may create a file
${HOME}/.Renviron with the following content:

    XPAUTH_PATH=/home/yourusername/xpauth.xpr

or the respective location of the license file in your environment.
