# Installation Options for Packages

Use the function `install.packages()` to install packages to use in TERR either in the stand-alone console, or in Spotfire. You can find packages in a variety of locations, including repositories, on reliable web sites, or stored locally. See the TERR help topic for `install.packages()` for more detail and examples.

Package Location | Description | Example
--- | --- | ---
TERR Archive Network (TRAN) repository | The default location, https://tran.tibco.com, for installing packages using `install.packages()`. Used for packages that have been customized to work specifically with TERR. Requires no further arguments. Note: Some packages customized and placed on TRAN require other packages not available on TRAN. Some of these packages cannot be installed using the TERR function `install.packages`, so the TRAN package cannot be successfully installed. If you encounter this situation, try building and installing the package using open-source R. For information on the installation differences between TERR and open-source R, see Specifying an older package from TRAN. |
    # install R Datasets Package found on TRAN:
    install.packages("datasets")
Posit CRAN mirror repository | The second value in `options("repos")` is initialized to a URL to the Posit repository, which contains snapshots of the CRAN packages on any given date. This URL specifies a fixed date on Posit and will not access CRAN package versions after that date. |
    #install package tidyr from Posit:
    install.packages("tidyr")
Comprehensive R Archive Network (CRAN) repository | CRAN is included in the default `options("repos")` to handle cases where the package is not available on TRAN or in the Posit repository (probably because it is a new package). If the default does not work, you can call `install.packages` setting the `repos` argument. One case where this option is useful is when accessing other repositories (such as Bioc). |
    # install rpart package from CRAN:
    install.packages("rpart", repos="https://cloud.r-project.org"))
In-house repository | You or someone in your organization has set up a CRAN-like repository (either on a network share or on a web server) using a tool like the drat package. All TERR or open-source R users in the organization can access the same package version from the repository. |
    #download and install from a
    # local web service using a URL:
    URL <- "https://mycompanysvc/mypackage")
    install.packages(URL)
Locally-available packages | If a trusted source gives you a package as a zip archive, you can put in on your computer and install it using `install.packages()`. |
    # install local newtree package
    # from a zip file in the working directory:
    install.packages("newtree_1.2.zip")
Trusted URL | If you are given a URL that contains a package you might want to use, and you trust the URL, you can pass the URL as the only argument to `install.packages()`. |
    #download from a custom URL and install
    # a custom package
    URL <- "https://customurl/mypackage")
    install.packages(URL)

Note:

The repositories contain binary packages (for Windows) and source packages (for Linux and Windows). You can easily install most binary and source packages in TERR. If you have problems building from source, then build the packages using open-source R before installing them into TERR. Note that TERR does not build binary packages from source packages that contain Java source code.

Platform | Package type | Notes
--- | --- | ---
Linux, Windows | Binary | Call `install.packages(pkgname)`. TERR installs the binary package into your specified package directory.
Linux | Source; no Java code, no C/C++ or Fortran code | Call `install.packages(pkgname)`. TERR builds the source package into a binary package and installs it into your specified package directory.
Linux, Windows | Source; C/C++ or Fortran code (no Java code) | Note: On Windows, first you must install the Rtools utilities package, which is maintained by Duncan Murdoch, and then update your PATH to specify the location of the utilities. If you have not already done so, install the package rinclude by calling `install.packages(rinclude)` Call `install.packages(pkgname)`. Note: See Installation Options for Packages for information on repositories accessed by `install.packages`. TERR builds the source package into a binary package and installs it into your specified package directory. If the package does not build and install, then try building it with open-source R, and then installing the binary as described here.
Linux | Source; Java code | Build the package using open-source R tools for building packages from source. The tools compile the source code to create the binary package. Call `install.packages(pkgname)`.

See the help for `install.packages(pkgname)` for more information.

Due to changes in open-source R version 3.5 and resulting compatibility changes in TERR 5.0, packages that are built with a version of TERR prior to 5.0 must be rebuilt.

- To install a binary package from a repository, always call `install.packages(pkgname)` from TERR. The `install.packages` function finds the correct binary version in the repository for your version of TERR. Manually downloading the binary package from CRAN can result in errors when you use it with TERR.
- To install a package from source, try installing it first with TERR (with `install.packages` in TERR or with `TERR CMD INSTALL` from a command line).
- To install a package from source that you cannot build with TERR, install the package with the version of open-source R tested with TERR.

To get more information about the packages on TRAN, run the following code in TERR:

    ap <- available.packages(contrib.url(getOption("repos")[1],
        getOption("pkgType")))
    # to print the entire matrix
    ap
    # to print just the package names
    row.names(ap)