English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Packages are a collection of R functions, sample data, precompiled code, including R programs, comment documents, examples, test data, etc.
R language related packages are generally stored in the 'library' directory under the installation directory, by default, some commonly used packages are brought by the installation of R language, of course, we can also add some packages to be used in the later stage.
You can find the complete related packages of R language here:https://cran.r-project.org/web/packages/available_packages_by_name.html
Next, we mainly introduce how to install R language packages.
We can use the following functions to view the installation directory of R packages:
> .libPaths() ]]1] "/Library/Frameworks/R.framework/Versions/4.0/Resources/library" >
We can use the following functions to view installed packages:
library()
The output result is as follows:
The R Base Package Bootstrap Functions (Originally by Angelo Canty The R Compiler Package compiler The R Datasets Package datasets Read Data Stored by 'Minitab', 'S', 'SAS', foreign 'SPSS', 'Stata', 'Systat', 'Weka', 'dBase', ... graphics The R Graphics Devices and Support for Colours grDevices and Fonts The Grid Graphics Package grid Functions for Kernel Smoothing Supporting Wand KernSmooth1995lattice Support Functions and Datasets for Venables and MASS Ripley's MASS
package:stats
package:datasets ]]1package:utils ]]4package:grDevices ]]7][ "package:methods" "Autoloads" "package:base"
You can use install.packages() function, in the format as follows:
install.packages("To Install Package Name")
We can directly set the package name, from CRAN website, as the following example shows us loading the XML package:
# Install XML package install.packages("XML")
Or we can directly get the package from CRAN Download the relevant packages and install them locally directly:
install.packages("./XML_3.98-1.3.zip")
Generally, we recommend using domestic mirrors in our country. The following example uses Tsinghua source for installation:
# Install XML package install.packages("XML", repos = "https://mirrors.ustc.edu.cn/CRAN/")
CRAN (The Comprehensive R Archive Network) mirror source configuration files include .Rprofile (located at ~/.Rprofile ).
Add the following statement at the end:
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
Open R to use this CRAN mirror source to install R software packages.
Newly installed packages need to be loaded into the R compilation environment before they can be used, in the format as follows:
library("Package Name")
The following example loads the XML package:
library("XML")