Skip to content

R and Apteco

Apteco's R integration allows you to run and score R models against FastStats data directly within FastStats, making it ideal for model evaluation and scoring.

Key features:

  • Scoring models—run R models against FastStats data and score FastStats records using the resulting model coefficients.
  • Model evaluation—evaluate R models alongside others in the FastStats Modelling Environment, including those created with built-in tools.
  • R code integration—execute R code that incorporates FastStats data for enhanced analytical capabilities.

Note

  • You can only use models supporting the PMML format.
  • Once a model is run, its coefficients are fixed. Updating the model with new data requires re-running it, though new records can still be scored with the existing model.
  • The performance of running R code that incorporates FastStats data may vary when using RCall and RScript expressions.
  • Models can be evaluated through pre-defined R Markdown reports, but interactive model exploration in an R console is not possible.

For further R documentation in the FastStats user help:

Install R for Windows

  1. Go to https://cran.r-project.org/bin/windows/base/.
  2. Click Download R-x.y.z for Windows.

    Download R for Windows

  3. Run the installer using default options.

Install Rserve

  1. Run R for Windows as Administrator.

    Run R as Administrator

    Note

    To run R for Windows as an Administrator, you need Administrator privileges. This is necessary to write to the default installation location for R packages. If you encounter any issues, see here for troubleshooting.

  2. Run install.packages("Rserve").

    Note

    'Rserve' is case-sensitive.

    RGui

    Next, select a CRAN mirror. Choose a mirror in your country or one that is close to your location.

    RGui location

  3. This installs Rserve as a package. A few additional steps are required to finish the installation:

    • The R console displays the saved location of the binary zip file, e.g. C:\Users\AppData\Local\Temp\Rtmp06VqMr\downloaded_packages

      Package Location

    • Locate rserve.exe in the zip file, e.g. Rserve_1.8-10\Rserve\libs\x64

      Rserve zip file

      Rserve Location

    • Copy this to the same directory that r.dll is located, e.g. C:\Program Files\R\R-4.2.1\bin\x64

      Rserve Copied Location

Configure the FastStats service

  1. In the FastStats Configurator, go to the R Integration section (under Integrations). Set the R Serve Program Files Directory to the same location as the previous step, for example: C:\Program Files\R\R-4.2.1\bin\x64.

    Rserve Program Files Directory

  2. Click Test to check if the integration is correctly set up.

    Rserve Test

  3. Restart the FastStats service before using the functionality in FastStats.

Troubleshooting

If testing the RServe setup in the FastStats Configurator fails:

When RServe runs it attempts to use the R_HOME environment variable to automatically detect the latest installed version of R. If that environment variable is not set, it will fall back to using registry keys created when R is installed. However, these registry keys are removed when any version of R is uninstalled, even if other versions remain on the system.

If testing the RServe setup fails, check whether these keys exist as expected—especially if you have previously removed other versions of R from your system. Alternatively, set the R_HOME environment variable to the directory where the latest version of R is installed, e.g. C:\Program Files\R\R-4.2.1.

Further details:

Optional steps

Additional package for creating R models in the FastStats Modelling Environment

Note

Before you begin, make sure you have set up the R integration for FastStats as explained above.

  1. Run R for Windows as an Administrator.
  2. Run install.packages("pmml").

    Note

    'pmml' is case-sensitive.

    pmml

    Binary packages

Additional packages for creating HTML reports with embedded R code

Note

Before you start, make sure you have set up the R integration for FastStats as explained above. Since the HTML reports work by creating R models in the Modelling Environment, you will need to install the 'pmml' package first.

  1. Run R for Windows as an Administrator.
  2. Run install.packages(c("knitr", "rmarkdown")).

    Note

    The package names are case-sensitive.

    Install Packages

R default packages

If you want to call a function from a package that isn't available by default in R on start-up, you would normally need a library() or require() call at the start of your script. While this is possible when using the RScript expression, it isn't possible for other aspects of the R integration (for example, when using the RCall expression, or when running an R model from the Modelling Environment).

To resolve this, you can change the default packages by editing the startup profile file.

  1. Find the profile file, either at the R_PROFILE environment variable, or at R_HOME/etc/Rprofile.site.
  2. Add the following command:

    Text Only
    options(defaultPackages=c(getOption("defaultPackages"),
    "myPackage1", "myPackage2", ...))
    

    where myPackage1, myPackage2, etc. are the names of the additional packages to load on start-up (this appends to the list of default packages rather than replacing them).

Further details: