# 4 Installation¶

In this section we discuss how to install and setup the MOSEK Rmosek Package.

Important

Before running this MOSEK interface please make sure that you:

• Installed MOSEK correctly. Some operating systems require extra steps. See the Installation guide for instructions and common troubleshooting tips.
• Set up a license. See the Licensing guide for instructions.

## 4.1 Windows Platforms¶

The interface documented here is part of the Rmosek package distributed from http://rmosek.r-forge.r-project.org/. Notice, however, that a pre-compiled binary version of it has not been distributed. Thus a small amount of configuration is necessary in order to install the package. It is not very difficult, but besides the basic installation of R you will need two pieces of software readily available through the Internet. In summary:

• MOSEK (the optimization library we interface to.
• Rtools (the tools needed for R package development

The following is a step-by-step guide through the installation of the package.

For additional help installing this interface, the section on packages in the R for Windows FAQ available on the CRAN website may be useful. The R Installation and Administration manual, also published by CRAN on their website, is another good source of information.

### 4.1.1 Setting Up the Target Machine¶

Assuming a working installation of R and MOSEK on the machine targeted for the R-to-MOSEK interface, the first step is to download Rtools for Windows. From this program you will need to install the component called R toolset, the Cygwin DLLs, and the R toolchain.

Note

R toolset and Cygwin DLLs will extend the Windows CMD with Unix-style commands, while the R toolchain (based on MinGW compilers) makes it possible to compile the C++ source code in the package. These components can be replaced by any other Unix-style shell and C++ build chain, but in the remaining guide the use of Rtools will be assumed.

After the installation of Rtools you will have to set the Windowsenvironment variable called PATH, in order to utilize the components. Assuming that the home directory of the Rtools installation was C:\Rtools, the entries shown below will have to be added to the existing PATH variable. Note that all entries in the PATH variable must be separated by a semicolon (;), and that all these entries have to represent folders that exist on the target machine.

• Add C:\Rtools\bin; to enable the R toolset and Cygwin DLLs.
• Add C:\Rtools\gcc-VERSIONbin; (for some VERSION) to enable the R toolchain.

That was it, but before we move on to the installation process, please ensure that the PATH variable also contains the bin folder of all MOSEK installations (32 and/or 64 bit) that you wish this interface to target. This is necessary for automatic configuration to work, and could look something like:

C:\Program\Mosek\8\tools\platform\win64x86\bin


### 4.1.2 Installing the Package with Automatic Configuration¶

Automatic configuration works equivalently to calling where mosek in the Windows CMD. It searches the environment variable called PATH for a folder with an executable called mosek. Note that if more than one such folder exists, only the one mentioned first in the PATH variable is chosen. It then determines the most ordinary of the available optimization libraries within this folder (typically mosek.lib or mosek64.lib), along with other relevant information. This configuration should work for all users installing the package on a single architecture (64 or 32 bit) and only requiring the ordinary optimization library. Otherwise, manual configuration of the package will be needed.

Now open R for the architecture (64 or 32 bit) you wish to install the package on. Make sure all your packages are up to date by writing update.packages(), and execute a command similar to the one shown below. This will install the Rmosek package:

install.packages("Rmosek", type="source", INSTALL_opts="--no-multiarch", repos="http://download.mosek.com/R/8")


Note that this package will have to be installed from source as it needs a static link to the MOSEK optimization library. This unfortunately means that dependencies (i.e. the Matrix package) will also be installed from source if new releases are available. Since it is more time-consuming to install the Matrix package from source, it is recommended to start with a call to update.packages(). The availability of the Matrix package should not be a problem, as it has been part of the standard R installation since version 2.9.0.

### 4.1.3 Installing the Package with Manual Configuration¶

If the automatic configuration does not suit your particular needs, or fails for some reason, a manual configuration may work instead. Unfortunately the configure.vars parameter of the install.packages command does not work on Windows, meaning that the files of the Rmosek source package will have to be edited. This can be difficult for non-savvy users, but have hopefully been documented sufficiently here.

How to manually configure the Rmosek package?

When you download the package from http://rmosek.r-forge.r-project.org/, it comes in a compressed archive called RMOSEK_VERSION.tar.gz for some version number VERSION. In order to configure the package, you will have to go through the following steps. A more thorough explanation of each step will be given afterwards.

1. Extract the archive into a directory.
2. Setup the local system descriptors, Localsys.txt, for each of the sub-architectures you will be using: 64 bit (e.g. x64) and/or 32 bit (e.g. i386). These files come with a guide written into them that clearly states how this should be done.
3. Compress the directory back into an archive.

The first step is to extract the rmosek_VERSION.tar.gz archive that you downloaded. This can either be done by using one of the many tools freely available online, or the tar command that was installed with Rtools. If you choose to use the tar command, you can extract the package by opening Windows CMD and executing a command similar to:

tar --no-same-owner -zxvf LOCATION/RMOSEK_VERSION.tar.gz


Remember to exchange LOCATION and VERSION with the correct values. For those not familiar with Windows CMD, we recommend the use of an external tool as this configuration can then be performed entirely within Windows Explorer.

The second step is to tell the package where to find the MOSEK optimization library. Open the extracted directory called Rmosek in either Windows CMD or Windows Explorer, and navigate to the subdirectory called src\setup. If you want to install a 64 bit version of the package (making an interface between 64 bit R and 64 bit MOSEK), open the folder x64 and follow the guide in Localsys.txt. If you want to install a 32 bit version of the package (making an interface between 32 bit R and 32 bit MOSEK), open instead the folder i386 and follow the guide in this Localsys.txt. An example of this is shown below

Listing 3 An example of local system descriptor. Click here to download.
##
## Greetings user of the R-to -MOSEK interface !
##
## If you are sitting on a WINDOWS 64 bit platform , this is the file that
## you will have to setup before this package can be installed .
## (see e.g. the R-to -MOSEK userguide )
##
##################
## Step 1 of 2 ##
##################
## Please substitute [ MOSEK_HOME_PATH ] below , with the path to the
## platform - specific folder within the MOSEK installation you want to
## use. Note that this path should contain a "bin" and a "h" folder .
## --------------------------------------------------------------------
## For example you can write:
## PKG_MOSEKHOME =C:\ Progra ~1\ Mosek \8\ tools\ platform \ win64x86
##
## If your computer contains the two directories :
## C:\ Progra ~1\ Mosek \8\ tools\ platform \ win64x86 \bin
## C:\ Progra ~1\ Mosek \8\ tools\ platform \ win64x86 \h
## --------------------------------------------------------------------
PKG_MOSEKHOME =[ MOSEK_HOME_PATH ]
##################
## Step 2 of 2 ##
##################
## Please substitute [ MOSEK_LIB_FILE ] below , with the name of the library
## you wish to use within the "bin" folder of your PKG_MOSEKHOME path.
## This "bin" folder must contain a file called [ MOSEK_LIB_FILE ]. lib.
## --------------------------------------------------------------------
## Continuing the example from above , you can write:
## PKG_MOSEKLIB = mosek64_8_0
##
## If your computer contains the file:
## C:\ Progra ~1\ Mosek \8\ tools\ platform \ win64x86 \bin\ mosek64_8_0 .lib
## --------------------------------------------------------------------
PKG_MOSEKLIB =[ MOSEK_LIB_FILE ]


The third and final step is to compress the (previously extracted and now altered) directory called Rmosek, back into the Rmosek_VERSION.tar.gz archive. Again you can either make use of the external tools from step one, or open the Windows CMD and execute a command similar to:

tar -zcvf Rmosek_VERSION.tar.gz Rmosek


How to install the manually configured Rmosek package?

Open R, either the console or the graphical user interface, for the architecture (64 or 32 bit) you wish to install the package on. Make sure all your packages are up to date by writing update.packages(), and execute the following command to install the Rmosek package::

install.packages("LOCATION/Rmosek_VERSION.tar.gz", repos=NULL, type="source", INSTALL_opts="--no-multiarch")


Remember to exchange LOCATION and VERSION with the correct values. The first argument should be the path to your manually configured package. The second argument tells that the package is local and not in an online repository. The third argument tells that it is a source package and so should be compiled. The fourth and final argument specifies that you only wish to install the package to the specific architecture (64 or 32 bit) of the opened R program. If you wish to install on both architectures, and did configure the package for both 32 and 64 bit, simply remove this last argument.

Notice that if you wish to uninstall the Rmosek package at some point, this can be done as for any other package with the command remove.packages(Rmosek).

## 4.2 UNIX-alike Platforms¶

The interface documented here is part of the Rmosek package distributed from http://rmosek.r-forge.r-project.org/. Notice, however, that a pre-compiled binary version of it has not been distributed (Such a binary would have to be built individually for each version of R and MOSEK). Thus a small amount of configuration is necessary in order to install the package. It is not very difficult, but besides the basic installation of R you will need MOSEK (the optimization library we interface to) readily available through the Internet.

The following is a step-by-step guide through the installation of the package.

For additional help on installing this interface, the section on installing packages in the manual R Installation and Administration, published on the CRAN website, is a good source of information.

### 4.2.1 Setting Up the Target Machine¶

We assume here that you have a working installation of R and MOSEK on the machine targeted for the R-to-MOSEK interface. The architectures (32 or 64 bit) of these two programs must be exactly the same for consistency. We further assume that the target machine have a build chain (e.g. GCC compilers for C/C++) installed.

For automatic configuration to work, the PATH variable should contain the bin folder of the single MOSEK installation (32 or 64 bit) that you wish this interface to target. This could look something like:

~/mosek/8/tools/platform/linux64x86/bin


If more than one bin folder from a MOSEK installation are specified, only the first one will be found by automatic configuration. Additional architectures can be added afterwards if necessary.

### 4.2.2 Installing the Package with Automatic Configuration¶

Automatic configuration works equivalently to calling which mosek in a terminal window. It searches the environment variable called PATH for a folder with an executable called mosek. Note that if more than one such folder exists, only the one mentioned first in the PATH variable is chosen. It then determines the most ordinary of the available optimization libraries within this folder (typically libmosek or libmosek64 with the extension .so or .dylib), along with other relevant information. This configuration should work for all users only installing the package on a single architecture (64 or 32 bit) and only requiring the ordinary optimization library. Otherwise, manual configuration of the package will be needed.

Now open R for the architecture (64 or 32 bit) you wish to install the package on. Make sure all your packages are up to date by writing update.packages(), and execute a command similar to the one shown below. This will install the Rmosek package::

install.packages("Rmosek", type="source", INSTALL_opts="--no-multiarch", repos="http://download.mosek.com/R/8")


Note that this package will have to be installed from source as it needs a static link to the MOSEK optimization library. This unfortunately means that dependencies (i.e. the ’Matrix’ package) will also be installed from source if new releases are available. Since it is more time-consuming to install the Matrix package from source, it is recommended to start with a call to update.packages(). The availability of the Matrix package should not be a problem, as it has been part of the standard R installation since version 2.9.0.

### 4.2.3 Installing the Package with Manual Configuration¶

Open R for one of the architectures (64 or 32 bit) you wish to install the package on. Make sure all your packages are up to date by writing update.packages(), and execute a command similar to the one shown below, with a correct definition of PKG_MOSEKHOME and PKG_MOSEKLIB. This will install the Rmosek package:

Remember to exchange the ... of both PKG_MOSEKHOME and PKG_MOSEKLIB with the correct values, explained as follows. The definition of the first argument, PKG_MOSEKHOME, should be the folder in your MOSEK installation, containing a bin and h subdirectory for the platform and architecture matching that of the opened R program. This could for instance look something like:

/home/username/mosek/8/tools/platform/linux64x86


Notice that auto-expansions such as $$\sim$$ does not work, and in case the folder definition contains spaces you will either have to wrap the definition in single-quotes or add backslashes in front of all spaces.

The definition of the argument PKG_MOSEKLIB should be the name of the optimization library in the bin subdirectory that you wish to utilize in the Rmosek package. This library will be statically linked to the package after a successful installation. Note that the name of the optimization library should be specified without the lib prefix, and without its file-extension. The PKG_RMOSEKLIB would thus normally be either mosek or mosek64 (linking to respectively libmosek.so and libmosek64.so, or respectively libmosek.dylib and libmosek64.dylib, depending on the Unix-alike system). Using mosek64 requires a 64 bit version of the opened R program and MOSEK installation, while mosek implies 32 bit.

How to install on multiple architectures?

If you wish to install the Rmosek package on multiple sub-architectures, you will first have to follow the above guide and install the package on one of the architectures (e.g. 32 or 64 bit). Afterwards as explained here, it can then be extended to other sub-architectures. This is also explained in R Installation and Administration (published on the CRAN website), in the subsection Multiple sub-architectures under Installing packages. For this to work you will need a preinstalled version of R and MOSEK in all the sub-architectures you wish this package to work with.

Open R in the sub-architecture you wish to extend your installation to, and execute a command similar to the one shown below::

install.packages("Rmosek", type="source", libs_only=TRUE, repos="http://download.mosek.com/R/8", configure.vars="PKG_MOSEKHOME=... PKG_MOSEKLIB=...")


Remember to exchange of the variables PKG_MOSEKHOME and PKG_RMOSELIB, so that declared MOSEK installation always correspond to the current sub-architecture of the opened R program.

How to install from an offline location?

This is almost the same a described above except that you would have to add the argument repos=NULL to tell R that it should not use an online repository. Also, instead of writing the package name Rmosek, you should write the entire file-location of the package source file which should look something like LOCATION/Rmosek_VERSION.tar.gz.

What are the command-line equivalents?

Sometimes you do not want to open R for all sub-architectures, but instead perform the installation directly from the console. Notice though, that this will require you to download the package source as you will only be able to install from an offline location in this way. In the two commands below you will have to replace SUBARCH_PATH, DIR and VERSION with the correct values, but doing so should be straight forward. Notice that on newer versions of R (>= 2.12), you can also use the call R --arch SUBARCH, instead of specifying the SUBARCH_PATH. Remember to exchange ... of the variables PKG_MOSEKHOME and PKG_MOSEKLIB, with the correct values as previously explained.

For the first architecture::

SUBARCH_PATH/R CMD INSTALL DIR/Rmosek_VERSION.tar.gz --no-multiarch --configure-vars="PKG_MOSEKHOME=... PKG_MOSEKLIB=..."


For subsequent architectures::

SUBARCH_PATH/R CMD INSTALL DIR/Rmosek_VERSION.tar.gz --libs-only --configure-vars="PKG_MOSEKHOME=... PKG_MOSEKLIB=..."
`