R

Starting with IBM® SPSS® Statistics 29, R 4.2 is a part of the product. It includes the IBM SPSS Statistics - Integration Plug-in for R and a set of extension commands that are implemented in R that provide capabilities beyond what is available with built-in SPSS Statistics procedures.

Note:

To determine which R packages are required for a specific R extension command , open the Extension Hub dialog (Extensions > Extension Hub), click the Installed tab, and then click More info for the desired extension. The required R packages are listed on the Extension Details dialog. R packages can be obtained from any of the R CRAN mirror sites, which are accessed from http://www.r-project.org/. Be sure to obtain the versions of the packages that match your R version. The version-specific packages are available from links on the "Contributed Packages" page of the CRAN mirror site.

Refer to the following introductory video for a brief overview on R programmability enhancements:

R runtime environment

Starting with IBM SPSS Statistics 28.0, an easily configurable R runtime environment is included with the product installation. The runtime environment is configured for use with SPSS Statistics. You can enter R code directly in the runtime environment console.

The R runtime environment is accessed by clicking the R for SPSS Statistics option (Start menu for Windows or Launchpad for macOS). The runtime environment can also be activated via command line by running the statisticsr.bat (Windows) or statisticsr (UNIX) script. The script is located in the IBM SPSS Statistics installation path (bin folder in UNIX).

Note: You may need to install the additional dependent libraries to ensure that the R runtime environment can run successfully on your UNIX server. The required libraries differ depending on the particular UNIX distribution and/or version. For example:

Linux Red Hat 8.3 server

# install libgfortran.so.3
yum install compat-libgfortran-48

# install libreadline.so.6
yum install readline

# install libicuuc.so.50 and libicui18n.so.50
yum install libicu

# install libpng15.so.15
yum install libpng15

ZLinux Red Hat 7.9 server

# install libgfortran.so.3
yum install libgfortran

PLinux Red Hat 8.3 server

# install libgfortran.so.3
yum install compat-libgfortran-48

# install libreadline.so.6
yum install readline

External R distribution

To use an external R distribution, in the File Locations tab set the R home directory field to the external distribution location (Edit > Options... > File Locations > R Location > Other installation of R).

For IBM SPSS Statistics Server, update the R 4.2 home path under the spssdxcfg.ini file's [R] section. The file is located in the SPSS Statistics installation path (bin folder on UNIX). For example:
[R]
HOME=
LIB_NAME=InvokeR

R 3rd party packages

The following steps explain the process of manually installing 3rd party R packages:

  1. Open a command line instance and go to the SPSS Statistics installation path (bin folder on UNIX).
  2. Launch the R runtime environment via the statisticsr script.
  3. In the R runtime environment, use the install.packages function to install 3rd party packages from CRAN. For example:

    Single package:

    install.packages(“package_name")

    Multiple packages:

    install.packages(c(“package_name1”, “package_name2”))

For more information, see https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/install.packages.

Known issues

The R runtime environment does not work after running the browser() function in SPSS Statistics drive R mode. A workaround for the issue is to launch the R runtime environment in a BEGIN/END PROGRAM R section in a syntax editor dialog. For example:
BEGIN PROGRAM R
END PROGRAM.