EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials R Programming Tutorial R Packages
 

R Packages

Priya Pedamkar
Article byPriya Pedamkar

Updated May 8, 2023

R Packages

 

 

Introduction to R Packages

R packages are a set of predefined functions as a library to be used while deploying the R program to care for reusability and less code approach R programs. R packages are externally developed and can be imported to the R environment in order to use the available function which belongs to that package. R packages are managed by the R community network known as CRAN for providing and provisioning with the R programming language. Apart from the standard R packages, there are several external packages available for use in the R program. One of the popular graphical packages in R is ggplot2.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Where do we Find Packages?

Packages are available on the internet through different sources. However, there are certain trusted repositories from where we can download the packages.

Here are the two important repositories that are available online.

  • CRAN(Comprehensive R Archive Network): This is the official R community with a network of FTP and webservers that contains the latest code and documentation of R. Before you post your packages online, it goes through a series of tests that adheres to CRAN policy.
  • GitHub: GitHub is another famous repository but not specific to R.The online community can share their packages with other people, and it is used for version control as well. GitHub is open-source and doesn’t have any review process.

List of Useful R Packages

There are several packages in R and can be downloaded from CRAN or GitHub. Below are the packages that can be used for specific purposes.

1. Loading the Data from External Sources

  • Haven: R reads and writes data from SAS.
  • DBI: To establish communication between the relational database and R.
  • RSQlite: It is used to read data from relational databases.

2. Data Manipulation

  • Dplyr: It is used for data manipulation like subsetting, provides shortcuts to access data and generates sql queries.
  • Tidyr – It is used to convert data into tiny formats.
  • stringr– manipulate string expressions and character strings.
  • lubridate- To work with data and time.

3. Data Visualization

  • Rgl: To work on 3D visualizations.
  • ggvis: To create and build grammar of graphics.
  • googlevis: To use google visualization tools in R.

4. Web-Based Packages

  1. XML: To read and write XML documents in R.
  2. Httpr: Work with http connections.
  3. Jsonlite: To read json data tables.

Obtaining R Packages

We can check the available packages that are present in R by using the below code.

  • available.packages(): There are approximately 5200 packages available in the CRAN network.

CRAN has task views that group packages under a particular topic.

Installing R Packages

We can install packages directly through IDE or through commands. To install packages, we use the below function and specify the package name.

Syntax:

install.packages() 

Code:

install.packages(“ggplot2”)

The above code installs the ggplot2 package and its dependent packages, if any.

We can install several packages at a time by specifying the package’s names under a character vector.

Syntax:

install.packages(c(“package 1”,”package 2”,”package 3”))

Code:

install.packages(c(“ggplot2”,”slidify”,”deplyr”))

Installing using R Studio

The advantage of using an R studio is it is GUI (Graphical User interface). We can choose the packages to install and the source of them.

We can go to tools -> Install packages.

Loading R Packages

After installing the R package, we need to load them into R to start making use of the installed packages.

We use the below function to load the packages.

Syntax:

library(package name)

Note: The package name need not be given in quotes.

Code:

library(ggplot2)

There are certain packages that display messages when loaded. Some of them don’t. We can see the details of the library installed with the help of the below code.

Code:

library(ggplot2)
search()

Output:

“package:lattice”    “package:ggplot2”    “package:makeslides”

“package:knitr”      “package:slidify”    “tools:rstudio”

Creating Your own Package

Before we create our own package, we should keep the below checklist in our mind before we proceed to create a package.

  • Organizing the code is one of the most important things while writing code in the package. We lose half the time searching for the code location instead of improving the code. Put all the files in a folder that is easily accessible.
  • Documenting the code helps you understand the purpose of the code. When we don’t revisit the code often, we forget why we have written the code in a certain way. It can also help people to understand your code better when shared with them.
  • Sharing the scripts through email has become archaic. The easy way is to upload your code and distribute it on GitHub. It is possible you get feedback that can help you enhance the code.

To create your own package, we have to install the devtools package.

Code:

install.packages("devtools")

To help with the documentation, we can use the below package.

Code:

install.packages("roxygen2")

After installing the package devtools, you can create your own package.

Code:

devtools::create ("packagename")

In the place of “packagename”, you can give the name you wish. You can now add your functions under this package.

You can create the same filename as your function name.

Syntax:

Devtools:create(“firstpackage”)

Distributing Package

You can distribute your package on GitHub by using the devtools package.

We use the below code to distribute our package on Github.

Code:

devtools::install_github("yourusername/firstpackage")

You can give your github username and package name you have created above.

Here are the Required Files for a Package

  • Functions
  • Documentation
  • Data

Once we have all the above files, we are good to post them in the repository.

Recommended Articles

This is a guide to R Packages. Here we discuss the list of useful R packages, installing packages using R studio and creating your own package, etc. You may also look at the following articles to learn more –

  1. What is R Programming Language?
  2. Careers in R Programming
  3. R Programming vs Python
  4. MySQL vs SQLite
  5. List of R Packages

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW