R Packages

R packages are a collection of R functions, compiled code, and sample data. They have been stored in a directory known library in the R environment. R programming install packages during installation. More packages are added later till they are needed for some specific tasks. Just default packages are available by default.

All the R language packages are available at R Packages.

Famous R Packages
Famous R Packages

To check, verify, and use the R packages, a list of commands is given below:

Check Available R Packages

To get the library locations that contains R packages the following command is used:

.libPaths()

Output

1 53

Get the list of all the packages installed

To get the list of all the packages installed in the R environment the following command is used:

To get all packages currently loaded in the R environment the following command is used:

search()

Output

1 54

Install a New Package

Here are two different methods to add new packages in R. The first one is installing directly from the CRAN directory and the second one is downloading and installing the package manually to your local system.

Install directly from CRAN

Mentioned below command take the packages directly from the CRAN webpage and installs the package. Select the one appropriate to your location.

Install package manually

Follow the below steps to install packages manually:

  1. Go to the link R packages to download the package need.
  2. Save the package as a .zip file in your location in local system.

After this, you can run the below command to install this package in the R.

How to load the package to the library?

Before a package can be used in the code, it must be loaded to the current R environment. You also need to load a package that is already installed previously but not available in the current environment.

The R packages should be loaded to the current R environment before use. You must load a package that is already existing but not available in the current environment.

A package is loaded using the following command :