How to install CRAN R packages?

A comprehensive guide on how to install CRAN R packages.

R packages consists of a collection of R functions, data sets and compiled code which adds value to the existing R-functionalities. They are stored in the 'library' directory in R-environment and developed by the community. For Example, "dplyr" is one of the commonly used packages in R which adds further functionalities with respect to working with dataframes.

There already exists some default packages in the local directory 'library' on your machine when you install R. We can see all the default packages by using code : 'library()'. If we want to add a new package, we can use three ways to do it:

  1. Directly from CRAN repository;

  2. From .zip file on your local machine;

  3. Via devtools package

This guide demonstrates how to install packages in r from CRAN repository which is an official repository consiting of different R-packages and web servers maintained by the R community

Explore Identifying Product Bundles from Sales Data Using R Language 

How to Install CRAN R packages?

Learn how to install R packages from CRAN in these simple steps.

Step 1: R Installing Packages

We use the command " install.packages("name of the package") " to install directly from CRAN repository. Below shows the code for installation of "dplyr".

install.packages("dplyr")

After running the command, we might recieve some messages which is based on the OS, dependencies installed and the status of the package.

If you want to install more than 1 package, just write them in a character vector in the command specified below:

Step 2: Loading a Package

We use the function "library()" to load the package. It is essential to load the package before we can use it in your code. To load a package, use the "library()" function:

library(MASS)

By loading the "MASS" package, you now have access to its functions and data sets, and you can use them in your R code.

How to update packages on CRAN?

In this section, the steps will guide you on how to update packages on CRAN in R.

Step-1 List Installed Packages

Open your R console or RStudio and use the command installed.packages() to list all the installed packages.

Step-2 Identify Outdated Packages

Look at the "Version" column in the output to identify packages with outdated versions.

Step-3 Update Individual Packages

To update a specific package, use the command install.packages("package_name"), replacing "package_name" with the name of the package you want to update.

Step- 4 Update All Packages

To update all installed packages, use the command update.packages(ask = FALSE). The ask = FALSE parameter ensures you don't get prompted for each package.

Step -5 Confirm Updates

Review the updates as they install. Once the process is complete, your packages will be up to date.

How to download R packages from CRAN wesbite?

In this section, you will learn how to download CRAN packages from the official website.

Step-1 Visit CRAN

Go to the official Comprehensive R Archive Network (CRAN) website at https://cran.r-project.org/.

Step-2 Navigate to Packages

Click on "Packages" in the website's menu.

Step-3 Choose a Package

Browse or search for the R package you want to download. Click on the package name to access its details.

Step-4 Select a Mirror

Choose a CRAN mirror location that is geographically close to you to download the package from. You can find the list of mirrors at https://cran.r-project.org/mirrors.html.

Step- 5 Download Package

Click on the "Package source" or "Windows" or "macOS" link to download the package to your computer.

How to install removed from CRAN packages in R?

Locate Package: If the package has been removed from CRAN, you might still find it on other repositories like GitHub or Bioconductor. Search for the package online to locate its source.

Step-1 Install Remotely

Use the devtools package to install packages directly from a repository. Run the command devtools::install_github("github_username/package_name"), replacing "github_username" with the username or organization and "package_name" with the package name on GitHub.

Step-2 Install from Local File

If you have the source code or package file on your local system, you can install it using install.packages(file_path, repos = NULL, type = "source"). Replace "file_path" with the path to the package file on your system.

Step-3 Install from Bioconductor

If the package is available on Bioconductor, you can install it using the BiocManager package. Run BiocManager::install("package_name"), replacing "package_name" with the package name.

Remember that installing packages from external sources may require additional dependencies and might not be as straightforward as CRAN packages.

Explore R projects with ProjectPro!

In the world of R programming, packages are the lifeblood that empowers your analyses and enhances your capabilities. Whether you're a data scientist, a statistician, or a business analyst, having a wide array of packages at your disposal is essential to harness the full potential of R.

ProjectPro recognizes the significance of comprehensive R packages in the data science domain. That's why we provide a wealth of projects and resources that allow you to dive deeper into the world of R programming. Whether you're exploring R package management, data analysis, or statistical modeling, ProjectPro's extensive library of projects has you covered.

So, why wait? Level up your R programming skills, explore new horizons, and embrace the power of data with ProjectPro's projects and courses. Dive into the exciting world of data science and big data elevate your skills to new heights.

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python

Personalized Medicine: Redefining Cancer Treatment
In this Personalized Medicine Machine Learning Project you will learn to classify genetic mutations on the basis of medical literature into 9 classes.

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

Deep Learning Project for Beginners with Source Code Part 1
Learn to implement deep neural networks in Python .

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Build a Customer Churn Prediction Model using Decision Trees
Develop a customer churn prediction model using decision tree machine learning algorithms and data science on streaming service data.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

CycleGAN Implementation for Image-To-Image Translation
In this GAN Deep Learning Project, you will learn how to build an image to image translation model in PyTorch with Cycle GAN.

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .