EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials R Programming Tutorial R Packages
Secondary Sidebar
R programming Tutorial
  • Basic
    • What is R Programming Language
    • Careers in R Programming
    • Install R
    • List of R Packages
    • Introduction of R Tools Technology
    • R Programming Language
    • DataSet in R
    • What is RStudio?
    • R-studio-Functions
    • R Packages
    • Time series?in R
    • R Data Types
    • R for data science
    • R Operators
    • R Data Frame
    • R Analytics Tool
    • R Tree Package
    • Vectors in R
  • Control statement
    • If Statement in R
    • If Else Statement in R
    • Else if in R
    • Switch Statement in R
  • Loops
    • Loops in R
    • For Loop in R
    • Nested For Loop in R
    • While Loop in R
    • Next in R
  • Chart/graphs
    • Graphs in R
    • Bar Charts in R
    • Pie Chart in R
    • Histogram in R
    • Line Graph in R
    • Plot Function in R
    • Scatterplot in R
    • R Boxplot labels
  • Regression in R
    • Simple Linear Regression in R
    • Linear Regression in R
    • Multiple Linear Regression in R
    • Logistic Regression in R
    • Poisson Regression in R
    • OLS Regression in R
    • P-Value in Regression
  • Anova in R
    • ANOVA in R
    • One Way ANOVA in R
    • Two Way ANOVA in R
  • Data Structure
    • R list
    • Arrays in R
    • Data Frames in R
    • Factors in R
    • R Vectors
  • Advanced
    • Statistical Analysis with R
    • R String Functions
    • Data Exploration in R
    • R CSV Files
    • KNN Algorithm in R
    • Sorting in R
    • lm Function in R
    • Hierarchical Clustering in R
    • R Normal Distribution
    • Binomial Distribution in R
    • Decision Tree in R
    • GLM in R
    • Arima Model in R
    • Linear Model in R
    • Predict Function in R
    • Survival Analysis in R
    • Standard Deviation in R
    • Statistical Analysis in R
    • Predictive Analysis?in R
    • T-test in R
    • Database in R
  • Programs
    • Functions in R
    • Boxplot in R
    • R Program Functions
    • Factorial in R
    • Random Number Generator in R
  • Interview question
    • R Interview Questions

R Packages

By Priya PedamkarPriya Pedamkar

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.

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.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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
Popular Course in this category
R Programming Training (13 Courses, 20+ Projects)
  13 Online Courses |  20 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Statistical Analysis Training (15 Courses, 10+ Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*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?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more