RLink`
RLink`

RInstallPackage

RInstallPackage[name,opts]

installs the R package name into the default R installation's package library.

RInstallPackage[name,rhome,opts]

installs the R package name for the R installation specified by rhome.

Details

  • RInstallPackage does not require a running RLink session to work.
  • The name must be a string name of an existing R package.
  • The path rhome must point to the R home directory of an R installation.
  • When rhome is not specified, or Automatic, RInstallPackage will try to extract its value using the following methods, tried in order: the currently running R installation, if any; the last successfully used R installation, if available; and the auto-discovered existing R installation (this option will only succeed if it discovers exactly one R installation). If no explicit value can be inferred for rhome, Failure is returned.
  • By default, RInstallPackage uses the standard default settings for the underlying R's install.packages() function, such as maximal timeout for package installation, type of installation (source/binary) and a number of other settings.
  • RInstallPackage will attempt to install all required dependencies, together with the package itself. Package installation will fail if any of the dependencies fail to install. Automatic removal of already partially installed dependencies is not guaranteed in this case.
  • When package dependencies are not available from the same package repository as the main package, it is the user's responsibility to pass all required R package repository URLs to RInstallPackage via the "Repositories" option.
  • If RInstallPackage fails to install the package, Failure is returned. When possible, the returned Failure will contain some details associated with the package installation failure.
  • To uninstall the package, use the "InstallationMethod" "Remove" option. Note that RInstallPackage will not automatically uninstall the dependencies. If the package has been installed into a nonstandard location, the location has to be passed explicitly via the "DestinationPath" option.
  • Calling RInstallPackage for an already installed package will do nothing except validate the package's installation. To reinstall the package, use the "Reinstall" True option.
  • The following options can be given:
  • "Repositories" Automatica list of URLs for R package repositories to use
    "InstallationMethod" Automaticthe installation method to be used; use "Remove" to uninstall the package
    "LocalSourcePath"Nonethe local path to the folder containing the package's source or binary installation
    "DestinationPath" Automaticthe local path to the folder in which to install the package
    "Reinstall" Falsewhether or not to reinstall an already installed package
    "DefaultRepository"Automaticthe URL for the default R package repository; the Automatic setting corresponds to https://cloud.r-project.org
    "DistributionType" Automaticthe type of R package distribution, which can be "Source", "Binary" or Automatic; this option is only useful for local installs (when an explicit value is passed for "LocalSourcePath")

Examples

open allclose all

Basic Examples  (1)

Load the RLink package:

Load the default R installation:

Install the R package RSQLite and all required dependencies:

Uninstall the package:

The same package installation could have been accomplished with an explicit R home location passed as a second argument to RInstallPackage:

Calling RInstallPackage on an R package that has been already installed simply validates the installation:

Reinstall the package:

Options  (6)

"Repositories"  (1)

Load the RLink package:

Install the Rcpp package using an alternative CRAN mirror. Here, the "DefaultRepository" None option is used to deliberately exclude the default repository:

"InstallationMethod"  (1)

Load the RLink package:

Install the RSQLite package:

Uninstall it:

Uninstalling a package that has not been installedor has already been uninstalledresults in a Failure:

"Reinstall"  (1)

Load the RLink package:

Install the RSQLite package:

If the package has been already installed, RInstallPackage does not reinstall it by default:

Passing "Reinstall"True forces RInstallPackage to reinstall the package:

RInstallPackage does not attempt to automatically uninstall package dependencies when uninstalling the package.

LocalSourcePath  (1)

Load the RLink package:

Download the binary distribution for the RSQLite package, for specific OS and R versions:

Now install the RSQLite package from the downloaded binary:

"DistributionType"  (1)

Load the RLink package:

This downloads the source for the RSQLite package:

This attempts to build the RSQLite package from the source. Depending on the operating system, various development tools (such as a C/C++ compiler etc.) may be required for the package source build to succeed:

"DestinationPath"  (1)

There are instances where one might want to install an R package into a nondefault location. For example, the default R package library might not be writable. In such cases, use the "DestinationPath" option to specify an alternative install location.

Load the RLink package and start an RLink session:

Create a temporary directory to install R packages into:

Install the RSQLite package into the specified folder:

By default, R will not be able to find packages installed into nondefault locations:

This defines a function that adds the supplied path to the R library search path:

Add your custom installation path to the R search path for the current R session:

Now the package is found:

To uninstall a package installed into a custom location, either add that location to the R search path, like in the previous example, or pass that location explicitly to RInstallPackage:

Neat Examples  (1)

Load RLink and start an RLink session:

Install the RSQLite package:

Load the package:

Next, define the wrapper function to execute SQL queries:

The following code executes a simple query using this package and returns the results:

Wolfram Research (2024), RInstallPackage, Wolfram Language function, https://reference.wolfram.com/language/RLink/ref/RInstallPackage.html.

Text

Wolfram Research (2024), RInstallPackage, Wolfram Language function, https://reference.wolfram.com/language/RLink/ref/RInstallPackage.html.

CMS

Wolfram Language. 2024. "RInstallPackage." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/RLink/ref/RInstallPackage.html.

APA

Wolfram Language. (2024). RInstallPackage. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/RLink/ref/RInstallPackage.html

BibTeX

@misc{reference.wolfram_2024_rinstallpackage, author="Wolfram Research", title="{RInstallPackage}", year="2024", howpublished="\url{https://reference.wolfram.com/language/RLink/ref/RInstallPackage.html}", note=[Accessed: 15-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_rinstallpackage, organization={Wolfram Research}, title={RInstallPackage}, year={2024}, url={https://reference.wolfram.com/language/RLink/ref/RInstallPackage.html}, note=[Accessed: 15-November-2024 ]}