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" Automatic a list of URLs for R package repositories to use "InstallationMethod" Automatic the installation method to be used; use "Remove" to uninstall the package "LocalSourcePath" None the local path to the folder containing the package's source or binary installation "DestinationPath" Automatic the local path to the folder in which to install the package "Reinstall" False whether or not to reinstall an already installed package "DefaultRepository" Automatic the URL for the default R package repository; the Automatic setting corresponds to https://cloud.r-project.org "DistributionType" Automatic the 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 allBasic Examples (1)
Load the default R installation:
Install the R package RSQLite and all required dependencies:
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:
Options (6)
"Repositories" (1)
Install the Rcpp package using an alternative CRAN mirror. Here, the "DefaultRepository" None option is used to deliberately exclude the default repository:
"InstallationMethod" (1)
Uninstalling a package that has not been installed—or has already been uninstalled—results in a Failure:
"Reinstall" (1)
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)
"DistributionType" (1)
"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:
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:
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