<div class="section-label"><span class="num">03</span> R</div>
<div class="section-title">R package + Prediction Engine <em>runtime</em>.</div>
In R you install two things: the **rbpengine** package, and the Prediction Engine runtime. The package alone is not enough to run predictions. The runtime and a [[License Key|license key]] are required.
<p> </p>
## What you need
- R 4.1 or newer
- A C compiler (the package builds from source): Xcode Command Line Tools on macOS, Rtools on Windows, or the usual build tools on Linux
- A license from CSA
| Operating system | Supported |
| --- | --- |
| macOS (Apple Silicon) | Yes |
| Linux (recent distributions) | Yes |
| Windows (64-bit) | Yes |
## 1. Install the R package
The client is on GitHub: [CambridgeSportsAnalytics/rbp-engine-r](https://github.com/CambridgeSportsAnalytics/rbp-engine-r). In R:
```r
install.packages(c("jsonlite", "remotes"))
remotes::install_github("CambridgeSportsAnalytics/rbp-engine-r")
library(rbpengine)
engine_available()
```
If the runtime is not installed yet, <span class="mono">engine_available()</span> returns <span class="mono">FALSE</span>. That is expected until step 2 is done.
## 2. Install the Prediction Engine runtime
In the same R session:
```r
rbpengine::install_engine()
engine_available() # TRUE
```
That downloads the current runtime for this machine and unpacks it where the package already looks.
C, MATLAB, and other FFI users can fetch the same files without R. See [[Install/Native Runtime|Native Runtime]].
## 3. Activate your license
With the runtime installed, continue to [[License Key]]. From R you can call the same tool as:
```r
rbpengine::license_info()
rbpengine::license_info("--setlicense", "RBP-LIC-1:…")
```
Prefer the R wrapper. If you want the binary in a shell, it is in the runtime prefix. See [[Install/Native Runtime#Where the runtime lives|Native Runtime]].
## Check that you are ready
```r
library(rbpengine)
engine_available() # should be TRUE after the runtime is installed
rbpengine::license_info()
```
<div class="btn-row center">
<a class="btn-primary" href="/Install/License%20Key">License Key</a>
<a class="btn-ghost" href="/Install/Native%20Runtime">Native runtime</a>
</div>
> [!note]- Optional: keep the same runtime later
> Skip this on a first install. <span class="mono">install_engine()</span> always fetches **latest**. Pass a version only when you need the same engine binary again (a paper, a production job, or matching another machine), and use the number CSA published, not a guess:
>
> ```r
> rbpengine::install_engine(version = "1.3.6")
> ```
>
> Native downloads use the same numbers: [[Install/Native Runtime|Native Runtime]].
## Update
Restart R, then run this in the new session. The session you already have open is still using the package it loaded at startup, and that package cannot replace the runtime library it has open.
```r
remotes::install_github(
"CambridgeSportsAnalytics/rbp-engine-r",
force = TRUE
)
library(rbpengine)
install_engine()
```
<span class="mono">install_engine()</span> replaces the runtime already on this machine. If this session has that library open, it closes the library first and writes the new files in the same place. Your license stays where it is.
The package version and the math library version are different numbers. The package version is the client. <span class="mono">math_lib_version()</span> reads the version compiled into the engine file and prints that version with the path of the file.
```r
packageVersion("rbpengine") # client
math_lib_version() # math library
```