Packages
The R community actively contributes to package development, resulting in a rapidly growing ecosystem of packages that extend the core functionality. This package ecosystem is one of its greatest strengths, providing an extensive collection of tools and functionalities that make R a powerful language for data analysis, statistics, and visualization.
Packages can be found hosted in different repositiories on the Internet. The main ones are:
- CRAN (Comprehensive R Archive Network): the official repository containing thousands of packages
- Bioconductor: a repository focused on bioinformatics
- GitHub: some developers host their R packages on GitHub
R packages in CRAN can be easily installed using the install.packages()
function. Once installed, packages are loaded into the R environment using the library()
function. We are going to see examples of of how to use both functions in this section.
CRAN
The power of R comes from its great wealth of excellent packages. These packages are managed in a central repository called CRAN (the Comprehensive R Archive Network). There are very strict protocols to follow to publish a package in CRAN, which includes an external review stage. As such, publishing an R package is a lot like publishing a paper, and so R packages on CRAN are mostly of a high standard, and come complete with documentation and tests. You can get an idea of what is needed to publish a package on CRAN by reading R Packages by Hadley Wickham and Jennifer Bryan. This excellent online book provides complete detail of how to write and publish an R package.
A good way to find the package you want is to use an R search service, such as rseek. You can search for individual package names, or even the kind of thing you want to do. As most R packages come with vignettes (web pages that show documentation and examples of how to use the package) this means you can quickly find both the package that achieves your goal, plus documentation and examples.