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

Gautam Vermani

Data Consultant at Confidential
linkedin profile url

Having worked in the field of Data Science, I wanted to explore how I can implement projects in other domains, So I thought of connecting with ProjectPro. A project that helped me absorb this topic... Read More

Relevant Projects

Build Time Series Models for Gaussian Processes in Python
Time Series Project - A hands-on approach to Gaussian Processes for Time Series Modelling in Python

End-to-End Speech Emotion Recognition Project using ANN
Speech Emotion Recognition using RAVDESS Audio Dataset - Build an Artificial Neural Network Model to Classify Audio Data into various Emotions like Sad, Happy, Angry, and Neutral

Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

Build ARCH and GARCH Models in Time Series using Python
In this Project we will build an ARCH and a GARCH model using Python

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.

Build Classification Algorithms for Digital Transformation[Banking]
Implement a machine learning approach using various classification techniques in Python to examine the digitalisation process of bank customers.

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.