# Package Management for the Service

If a data function author in your organization creates a Spotfire analysis that uses packages from a public or private repository, then the administrator must make sure that the packages are installed on Spotfire Server.

Important: Packages must be installed in the same type of environment as where they are executed. For example, if you built the Docker image for your containerized TERR service, make sure the packages are installed on a node manager running the same operating system as the containerized engines. If this is not possible, then see the workaround options in Troubleshooting the Service.
TERR programmers in your organization can develop their own packages or take advantage of some of the thousands of compatible packages developed by other TERR programmers, and then share the analyses that use those functions with Spotfire users in your organization.
Note: Data function authors must be in the Script Author group to create and save data functions that use TERR.

The largest and most commonly-used, curated repository for R packages is the Comprehensive R Archive Network (CRAN). Most packages that are not installed with the TERR service are downloaded from this repository.

Testing results for CRAN package compatibility are available for Windows and Linux.

Important: By default, the TERR engine runs in "Restricted Execution" mode, where attempting to execute certain operations defined as restricted (such as installing packages or performing any I/O operation) generates an error. This option is meant to protect your system from potentially malicious code running in the global environment. To enable your data function developers to upload and use packages, you must allow the TERR service to run in unrestricted mode. For more information about restricted mode, see the TERR language reference for `evalREX`. For more information on setting trust options for data functions and scripts in Spotfire, see the topic Script and Data Function Trust in the Spotfire Analyst Help.

The service provides the following ways to add packages.

Installing packages directly on the node manager computer, using the TERR engine installed there.
  This way makes the packages accessible to a TERR service engine running on a node when the engine session is created. This method is the most efficient, because calling `install.packages()` directly on the server ensures that all dependent packages are also installed. If you use this method, you must specify the package path in the custom configuration file. See Configuring the Service for more information.
Building an SPK that contains custom-designed or CRAN packages that are compatible with the supported TERR engine.
  The SPK is uploaded to the server. Packages are stored as part of the deployment and are accessible to the TERR service engine running on a node when the engine session is created. This way of installing packages requires that you create and manually maintain a Debian Control File (DCF) that lists all packages to be installed, including dependent packages. Because the DCF controls SPK versioning, it provides better package governance than directly uploading to the server. See The Spotfire Package (SPK) for detailed instructions for creating an SPK and managing its packages. See Installing R Packages Manually for more information.
  Important: If you create an SPK on a computer other than the computer where the node manager is installed, then be sure to use a computer that is running same operating system as the computer where the packages are going to be deployed. For example, If you are creating an SPK on Linux, be sure your Linux OS type and version are the same as that of the computer where the node manager is installed.
Configuring the `packagePath` in `custom.properties` to point to a mounted drive or directory that contains packages that are compatible with the TERR engine.
  This way of package management is the most controlled, where only packages in the specified repository are used. Data function authors must also configure their systems to write their data functions to use these packages.

Regardless of which way your organization uses to manage packages, the administrator who installs the TERR packages must do the following.

- Coordinate with the author of a Spotfire data function to ensure that all TERR packages that are used in the analysis are installed on the host computer running the nodes on which the TERR service is running.
- Ensure that all required and dependent packages associated with the needed packages are also installed. (The author of the data function can provide the administrator with this information.)
  Note: The SPK package management tools handle installing all required and dependent packages needed by a specified package.

Important: If you install packages from the TERR console, or using TERR provided with Spotfire Analyst, you usually install them using a script such as `install.packages(c("packagename", "packagename"))`. However, if you try to install packages using such a script from the TERR service then the packages are not available to the entire service. To ensure that the packages you need are available to the entire service, you need to install them on the host computer running the TERR service.