ropenblas: Download, Compile and Link OpenBLAS Library with R

last CRAN_Status_Badge total month

The ropenblas is a package designed to facilitate the linking of the library OpenBLAS with the language R. The package, which works only for Linux systems, will automatically download the latest source code from the OpenBLAS library and compile the code. The package will automatically bind the language R, through the ropenblas() function, to use the OpenBLAS library. Everything will be done automatically regardless of the Linux distribution you are using.

You can also specify older versions of the OpenBLAS library. Automatically, if no version is specified, the ropenblas package will consider the latest version of the library OpenBLAS.

Considering using the OpenBLAS library rather than the BLAS may bring extra optimizations for your code and improved computational performance for your simulations, since OpenBLAS is an optimized implementation of the library BLAS.

Some of the reasons why it is convenient to link R language to the use of BLAS optimized alternatives can be found here. Several other benchmarks that point to improved computing performance by considering the library OpenBLAS can be found on the internet.

The ropenblas package, by rcompiler() function is also useful if you want to install different versions of the R language. The different versions, specified by the user of the R language, will be compiled and will also be linked to the OpenBLAS library. If you want to switch between compiled versions of the R language, no compilation is needed anymore. This allows you to avoid having to get your hands dirty with tedious operating system settings, regardless of your GNU/Linux distribution. Another great use of the rcompiler() function is that you will not be dependent on updating your GNU/Linux distribution repositories and you can always have the latest version of the R language.

The use of the ropenblas package will return warnings that help you proceed with the use of the functions. If your internet is not working or if any dependency on the operating system is not present, the package will let you know.


You must install the following dependencies on your operating system (Linux):

1 - GNU Make: GNU Make utility to maintain groups of programs;

2 - GNU GCC Compiler (C and Fortran): The GNU Compiler Collection - C and Fortran frontends.

Do not worry that you will be notified if any of these dependencies are not installed.


Installing the ropenblas library is easy and will require you to have installed the devtools package. This will allow you to install the ropenblas package directly from GitHub. To install, after installing the devtools package, do:

devtools::install_github(repo = "prdm0/ropenblas", force = TRUE)



Note: If you want to access the latest features of the ropenblas package, install it using the first procedure.

Using the package

The ropenblas package currently provides five functions: ropenblas(), rcompiler(), last_version_openblas(), last_version_r() and link_again(). First of all, do:


‘ropenblas’ function:

Installing, compiling, and linking the OpenBLAS version 0.3.9 library to the R language:

ropenblas(x = "0.3.9")



Your linux operating system may already be configured to use the OpenBLAS library. Therefore, most likely R will already be linked to this library. To find out if the R language is using the OpenBLAS library, at R, do:


If R is using the OpenBLAS library, something like /any_directory/ should be returned. Therefore, there should be the name openblas in the shared object returned (file extension .so).

If the ropenblas() function can identify that the R language is using the version of OpenBLAS you wish to configure, a warning message will be returned asking if you really would like to proceed with the configuration again.

The ropenblas() function will download the desired version of the library OpenBLAS, compile and install the library in the /opt directory of your operational system. If the directory does not exist, it will be created so that the installation can be completed. Subsequently, files from the version of BLAS used in R will be symbolically linked to the shared object files of the library version OpenBLAS compiled and installed in /opt.

You must be the operating system administrator to use this library. Therefore, do not attempt to use it without telling your system administrator. If you have the ROOT password, you will be responsible for everything you do on your operating system.

You will not necessarily have to run ropenblas() on every section of R. Almost always it will not be necessary. However, it may be that the R is updated by the operating system (GNU/Linux). Thus, it may be that in this update the R unlink with the OpenBLAS library. Therefore, from time to time check using the command extSoftVersion()["BLAS"] if the link with OpenBLAS is correct, otherwise run the command ropenblas() again.

‘last_version_r’ function:

Given the higher version, the function will return the latest stable version of the R language. See the following example:

> last_version_r()
[1] "4.0.0"

[1] "4.0.0"

[1] 1


> last_version_r(major = 3L)
[1] "3.6.3"

 [1] "3.0.0"         "3.0.1"         "3.0.2"         "3.0.3"         "3.1.0"         "3.1.1"         "3.1.2"         "3.1.3"        
 [9] "3.2.0"         "3.2.1"         "3.2.2"         "3.2.3"         "3.2.4-revised" "3.2.4"         "3.2.5"         "3.3.0"        
[17] "3.3.1"         "3.3.2"         "3.3.3"         "3.4.0"         "3.4.1"         "3.4.2"         "3.4.3"         "3.4.4"        
[25] "3.5.0"         "3.5.1"         "3.5.2"         "3.5.3"         "3.6.0"         "3.6.1"         "3.6.2"         "3.6.3"        

[1] 32

Note: If major = NULL, the function will consider the major release number.

‘last_version_openblas’ function:

The last_version_openblas() function automatically searches OpenBLAS library versions in the official GitHub project.

> last_version_openblas()
[1] "0.3.9"

 [1] "0.1.0"       "0.1.1"       "0.1alpha1"   "0.1alpha2"   "0.1alpha2.1" "0.1alpha2.2" "0.1alpha2.3"
 [8] "0.1alpha2.4" "0.1alpha2.5" "0.2.0"       "0.2.1"       "0.2.10"      "0.2.10.rc1"  "0.2.10.rc2" 
[15] "0.2.11"      "0.2.12"      "0.2.13"      "0.2.14"      "0.2.15"      "0.2.16"      "0.2.16.rc1" 
[22] "0.2.17"      "0.2.18"      "0.2.19"      "0.2.2"       "0.2.20"      "0.2.3"       "0.2.4"      
[29] "0.2.5"       "0.2.6"       "0.2.7"       "0.2.8"       "0.2.9"       "0.2.9.rc1"   "0.2.9.rc2"  
[36] "0.3.0"       "0.3.1"       "0.3.2"       "0.3.3"       "0.3.4"       "0.3.5"       "0.3.6"      
[43] "0.3.7"       "0.3.8"       "0.3.9"      

[1] 45

‘rcompiler’ function:

This function is responsible for compiling a version of the R language. The x argument is the version of R that you want to compile. For example, x = "4.0.0" will compile and link R-4.0.0 version as the major version on your system. By default (x = NULL) will be compiled the latest stable version of the R.

For example, to compile the latest stable version of the R language, do:


Regardless of your GNU/Linux distribution and what version of R is in your repositories, you can have the latest stable version of the R language compiled into your computer architecture.

You can use the rcompiler() function to compile different versions of R. For example, running rcompiler(x = "3.6.3") and rcompiler() will install versions 3.6.3 and 4.0.0 on its GNU/Linux distribution, respectively. If you are in version 4.0.0 of R and run the code rcompiler(x = "3.6.3") again, the function will identify the existence of version 3.6.3 in the system and give you the option to use the binaries that were built in a previous compilation. This avoids unnecessarys compilations.

In addition to the x argument, thercompiler() function has two other arguments that will allow you to change and pass new compilation flags. Are they:

  1. with_blas: This argument sets the --with-blas flag in the R language compilation process and must be passed as a string. Details on the use of this flag can be found here. If with_blas = NULL (default), then it will be considered:

    ./configure --prefix=/opt/R/version_r --enable-memory-profiling --enable-R-shlib --enable-threads=posix
    --with-blas="-L/opt/OpenBLAS/lib -I/opt/OpenBLAS/include -lpthread -lm"

    Most likely, you will have little reason to change this argument. Unless you know what you’re doing, consider with_blas = NULL. Do not change the installation directory, that is, always consider --prefix = /opt/R/version_r, whereversion_r is a valid version of R. For a list of valid versions of R, run the last_version_r(). Installing R in the /opt/R/version_r directory is important because some functions in the package require this. Both the R language and the OpenBLAS library will be installed in the /opt directory. If this directory does not exist in your GNU/Linux distribution, it will be created;

  2. complementary_flags: String (complementary_flags = NULL by default) for adding complementary flags in the R language compilation process. Passing a string to complementary_flags will compile it in the form:

     ./configure --with-blas="..." complementary_flags

The link_again function links again the OpenBLAS library with the R language, being useful to correct problems of untying the OpenBLAS library that is common when the operating system is updated.

The function link_again be able to link again the R language with the OpenBLAS library. Thus, link_again will only make the relinkagem when in some previous section of R the ropenblas function has been used for the initial binding of the R language with the OpenBLAS library.

For example, to relink the OpenBLAS library with the R language, do:


If restart_r = TRUE (default), a new section of R is started after linking the OpenBLAS library.

In situations where there was a disconnection due to an update of the operating system, the ropenblas function can be used to relink the OpenBLAS library with the R language, however, it will be necessary to compile the OpenBLAS library again. If you are interested in recompiling the OpenBLAS library and linking with R, use the ropenblas function. If the interest is to take advantage of a previous compilation of the OpenBLAS library, the function link_again may be useful.

Advantages of using ropenblas package:

Some advantages of using the ropenblas library: