Unit 3-1
Unit 3-1
Object-Oriented Programming (OOP) is the most popular programming language. With the help of oops
concepts, we can construct the modular pieces of code which are used to build blocks for large systems. R is a
functional language, and we can do programming in oops style. In R, oops is a great tool to manage the
complexity of larger programs.
S3
In oops, the S3 is used to overload any function. So that we can call the functions with different names and it
depends on the type of input parameter or the number of parameters.
S4 is the most important characteristic of oops. However, this is a limitation, as it is quite difficult to debug.
There is an optional reference class for S4.
In R, classes are the outline or design for the object. Classes encapsulate the data members, along with the
functions. In R, there are two most important classes, i.e., S3 and S4, which play an important role in
performing OOPs concepts.
Let's discuss both the classes one by one with their examples for better understanding.
Classes in R
S3 Class
An S3 class is one of the most used classes in R. This class is easy to
implement and many predefined classes are of this type.
The object of an S3 class is a list having class attributes assigned with some
names. The component of the list is represented by the member variable of
the object.
Creating S3 Class
Example
Open Compiler
# Creating list
myList <- list(Name ="Bhuwanesh", Enrollment_Number = 3496303119,
Course = "Btech", Branch = "Information Technology")
# class
class(myList) <- "University"
myList
Output
$Name
[1] "Bhuwanesh"
$Enrollment_Number
[1] 3496303119
$Course
[1] "Btech"
$Branch
[1] "Information Technology"
attr(,"class")
[1] "University"
Generic Function
methods(summary)
We can create our own generic function in R. Let us consider the following
program that creates a list by the name “myList” and then creates a class out
of it.
Example
Now we display the summary of this class using the summary() function −
Open Compiler
# Create a list
myList <- list(Name ="Bhuwanesh",
Enrollment_Number = 3496303119,
Course = "Btech",
Branch = "Information Technology")
Attributes
Example
Let us consider the following program illustrating the working of this function
−
Open Compiler
# Create a list
myList <- list(Name ="Bhuwanesh",
Enrollment_Number = 3496303119,
Course = "Btech",
Branch = "Information Technology")
# Define a class
class(myList) <- "University"
# Display attributes
print(attributes(myList))
Output
$names
[1] "Name" "Enrollment_Number" "Course"
[4] "Branch"
$class
[1] "University"
We can also apply our own attributes to an object with the help of the attr()
function Let us consider the following illustrating the working of this function
−
Example
Open Compiler
# Create a list
myList <- list(Name ="Bhuwanesh",
Enrollment_Number = 3496303119,
Course = "Btech",
Branch = "Information Technology")
# Define class
class(myList) <-"University"
# Display attribute
print(attributes(myList))
Output
$names
[1] "Name" "Enrollment_Number" "Course"
[4] "Branch"
$class
[1] "University"
$Grade
[1] "A"
Inheritance in S3 Class
Example
Open Compiler
# Create a list
myList1 <- list(Name ="Bhuwanesh", Enrollment_Number = 3496303119,
Course = "Btech", Branch = "Information Technology")
# Create a list
myList2 <- list(College_Rank = 14, State = 'Uttarakhand')
print(myList2)
Output
$College_Rank
[1] 14
$State
[1] "Uttarakhand"
attr(,"class")
[1] "College" "University"
As you can see in the output, class “College” inherits the class “University”.
Example
Now let us try to access and modify the components of the base class
“University” using an object of the base class “College” −
Open Compiler
# Create a list
myList1 <- list(Name ="Bhuwanesh", Enrollment_Number = 3496303119,
Course = "Btech", Branch = "Information Technology")
# Define a class
class(myList1) <- "University"
print(myList2)
Output
$College_Rank
[1] 14
$State
[1] "Uttarakhand"
$Name
[1] "Harshit"
attr(,"class")
[1] "College" "University"
You can see in the output, the “Name” property has been modified to
“Harshit”.
S4 Class
R allows us to use another peculiar type of class known as the “S4” class.
This class contains the predefined definition. This class contains functions to
define methods and generics. This class also provides us with auxiliary
functions to define generics and methods.
# Define a list
myList1 <- list(Name ="Bhuwanesh",
Enrollment_Number = 3496303119,
Course = "Btech",
Branch = "Information Technology")
print(myObject)
Output
Slot "Enrollment_Number":
[1] 3496303119
Slot "Course":
[1] "Btech"
Slot "Branch":
[1] "Information Technology"
Inheritance in S4 class
Inheritance is one of the most important pillars of object-oriented
programming language which allow one class to inherit the properties of
another class. This feature leads to benefits like code-reusability.
The S4 class contains a proper pattern for its definition. The derived classes
are capable enough to inherit attributes and methods from the base class. In
order to achieve this we can
Example
# Set class
setClass("University",
slots = list(Name = "character",
Enrollment_Number = "numeric",
Branch = "character")
)
# Set methods
setMethod("show", "University",
function(object){
cat(object@Name, "")
cat(object@Enrollment_Number, "")
cat(object@Branch, "")
}
)
# Inherit
setClass("College",
slots = list(Grade= "character"),
contains = "University"
)
# Define the object
object <- new("College", Name = "Bhuwanesh Nainwal",
Branch="Information Technology",
Enrollment_Number = 3496303119)
Bhuwanesh Nainwal
3496303119
Information Technology
R Reference Class
How to define a reference class?
Defining reference class is similar to defining a S4 class. Instead
of setClass() we use the setRefClass() function.
> setRefClass("student")
> s$name
[1] "John"
> s$age
[1] 21
> s$GPA
[1] 3.5
But this is not the case with reference objects. Only a single copy exist and
all variables reference to the same copy. Hence the name, reference.
This can cause some unwanted change in values and be the source of
strange bugs. We need to keep this in mind while working with reference
objects. To make a copy, we can use the copy() method made availabe to
us.
All reference class have some methods predefined because they all are
inherited from the superclass envRefClass .
> student
Generator for class "student":
Class fields:
Name: name age GPA
Class: character numeric numeric
Class Methods:
"callSuper", "copy", "export", "field", "getClass", "getRefClass",
"import", "initFields", "show", "trace", "untrace", "usingMethods"
Reference Superclasses:
"envRefClass"
We can see class methods like copy() , field() and show() in the above
list. We can create our own methods for the class.
This can be done during the class definition by passing a list of function
definitions to methods argument of setRefClass() .
Note that we have to use the non-local assignment operator <<- since age
isn't in the method's local environment. This is important.
Using the simple assignment operator <- would have created a local
variable called age , which is not what we want. R will issue a warning in
such case.
Here is a sample run where we use the above defined methods.
With the help of the S3 class, we can take advantage of the ability to implement the generic function OO.
Furthermore, using only the first argument, S3 is capable of dispatching. S3 differs from traditional
programming languages such as Java, C ++, and C #, which implement OO passing messages. This makes S3
easy to implement. In the S3 class, the generic function calls the method. S3 is very casual and has no formal
definition of classes.
Creating an S3 class
In R, we define a function which will create a class and return the object of the created class. A list is made with
relevant members, class of the list is determined, and a copy of the list is returned. There is the following
syntax to create a class
Example
Output
There is the following way in which we define our generic function print.
1. print
2. function(x, ...)
3. UseMethod("Print")
When we execute or run the above code, it will give us the following output:
Like print function, we will make a generic function GPA to assign a new value to our GPA member. In the
following way we will make the generic function GPA
Once our generic function GPA is created, we will implement a default function for it
After that we will make a new method for our GPA function in the following way
1. GPA(s)
Output
Inheritance in S3
Inheritance means extracting the features of one class into another class. In the S3 class of R, inheritance is
achieved by applying the class attribute in a vector.
For inheritance, we first create a function which creates new object of class faculty in the following way
1. faculty<- function(n,a,g) {
2. value <- list(nname=n, aage=a, GPA=g)
3. attr(value, "class") <- "faculty"
4. value
5. }
Now, we will create an object of class InternationalFaculty which will inherit from faculty class. This process will
be done by assigning a character vector of class name as:
so,
1. # create a list
2. fac <- list(name="Shubham", age=22, GPA=3.5, country="India")
3. # make it of the class InternationalFaculty which is derived from the class Faculty
4. class(fac) <- c("InternationalFaculty","Faculty")
5. # print it out
6. fac
When we run the above code which we have discussed, it will generate the following output:
We can see above that, we have not defined any method of form print. InternationalFaculty (), the method
called print.Faculty(). This method of class Faculty was inherited.
1. print.InternationalFaculty<- function(obj1) {
2. cat(obj1$name, "is from", obj1$country, "\n")
3. }
The above function will overwrite the method defined for class faculty as
1. Fac
getS3method and getAnywhere function
There are the two most common and popular S3 method functions which are used in R. The first method
is getS3method() and the second one is getAnywhere().
S3 finds the appropriate method associated with a class, and it is useful to see how a method is implemented.
Sometimes, the methods are non-visible, because they are hidden in a namespace. We use getS3method or
getAnywhere to solve this problem.
getS3method
getAnywhere function
1. getAnywhere("simpleloess")
2) S4 Class
The S4 class is similar to the S3 but is more formal than the latter one. It differs from S3 in two different ways.
First, in S4, there are formal class definitions which provide a description and representation of classes. In
addition, it has special auxiliary functions for defining methods and generics. The S4 also offers multiple
dispatches. This means that common functions are capable of taking methods based on multiple arguments
which are based on class.
Creating an S4 class
In R, we use setClass() command for creating S4 class. In S4 class, we will specify a function for verifying the
data consistency and also specify the default value. In R, member variables are called slots.
To create an S3 class, we have to define the class and its slots. There are the following steps to create an S4
class
Step 1:
In the first step, we will create a new class called faculty with three slots name, age, and GPA.
There are many other optional arguments of setClass() function which we can explore by using ?
setClass command.
Step 2:
In the next step, we will create the object of S4 class. R provides new() function to create an object of S4 class.
In this new function we pass the class name and the values for the slots in the following way:
The setClass() function returns a generator function. This generator function helps in creating new objects. And
it acts as a constructor.
Now we can use the above constructor function to create new objects. The constructor in turn uses the new()
function to create objects. It is just a wrap around. Let's see an example to understand how S4 object is created
with the help of generator function.
Example
Output
Inheritance in S4 class
Like S3 class, we can perform inheritance in S4 class also. The derived class will inherit both attributes and
methods of the parent class. Let's start understanding that how we can perform inheritance in S4 class. There
are the following ways to perform inheritance in S4 class:
Step 1:
In the first step, we will create or define class with appropriate slots in the following way:
1. setClass("faculty",
2. slots=list(name="character", age="numeric", GPA="numeric")
3. )
Step 2:
After defining class, our next step is to define class method for the display() generic function. This will be done
in the following manner:
1. setMethod("show",
2. "faculty",
3. function(obj) {
4. cat(obj@name, "\n")
5. cat(obj@age, "years old\n")
6. cat("GPA:", obj@GPA, "\n")
7. }
8. )
Step 3:
In the next step, we will define the derived class with the argument contains. The derived class is defined in the
following way
1. setClass("Internationalfaculty",
2. slots=list(country="character"),
3. contains="faculty"
4. )
In our derived class we have defined only one attribute i.e. country. Other attributes will be inherited from its
parent class.
When we did show(s), the method defines for class faculty gets called. We can also define methods for the
derived class of the base class as in the case of the S3 system.
An object is a data structure having some attributes and methods which act
on its attributes.
Class is a blueprint for the object. We can think of class like a sketch
(prototype) of a house. It contains all the details about the floors, doors,
windows etc. Based on these descriptions we build the house.
House is the object. As many houses can be made from a description, we
can create many objects from a class. An object is also called an instance
of a class and the process of creating this object is called instantiation.
They have their own features and peculiarities and choosing one over the
other is a matter of preference. Below, we give a brief introduction to them.
S3 Class
S3 class is somewhat primitive in nature. It lacks a formal definition and
objects of this class can be created simply by adding a class attribute to it.
This simplicity accounts for the fact that it is widely used in the R
programming language. In fact most of the R built-in classes are of this
type.
Example 1: S3 Class
Output
$name
[1] "John"
$age
[1] 21
$GPA
[1] 3.5
attr(,"class")
[1] "student"
S4 Class
S4 class is an improvement over the S3 class. They have a formally
defined structure which helps in making objects of the same class look
more or less similar.
Class components are properly defined using the setClass() function and
objects are created using the new() function.
See R programming S4 Class section for further details.
Example 2: S4 class
Output
Slot "age":
[1] 21
Slot "GPA":
[1] 3.5
Output
Objects are created by setting Objects are created Objects are created using
the class attribute using new() generator functions
oriented language. Everything in R is considered an object. Each object has one or more attributes. Most of the
R objects have an attribute which is the “class” of the object. R provides a bundle of classes for statistical
programming. Everything in R is an object list, vector, data frame, factor, array, etc. An object is a collection of
data members associated with functions. Objects are the Basic Building of a program. An object is also
called an Instance of class. The process of creating an object from a class is called instantiation. Objects
have their attributes like class, dimnames,names,dim,comments etc. An object has a real Existence.
Classes in R
A class is a description of a thing and an object is an instance of a class. A class describes an object type by
mentioning the properties, behavior, and relationship of the object with other objects. The term methods can be
A class is a blueprint for the object. For example consider a sketch of a house with all details regarding its
floor, windows, doors, bedrooms, kitchen, etc based on the model in which the house is constructed.
Let us understand a simple example to differentiate an object and a class. Consider a class Person with
Irina, John, and Adam but they belong to the same class Person. The common behavior of a person like
walk(),eat(),,sleep() forms methods to implement or the actions of the objects. So we can say the class is a
blueprint that is responsible for providing Different Properties to objects and providing different methods to
There are three separate systems of object orientation in R.The three systems are the following:-
1. S3 class
2. S4 class
3. Reference class
Each system is used independently of the other. Developers of new projects are encouraged to use s4 style
classes. They are extensively used in Bioconductor projects. Many developers use S3 classes because they are
1. S3 Classes in R
S3 carries out a style of object-oriented programming known as generic function OO. This is different from most
programming dialects, similar to Java, C++, and C#, which execute message-passing OO.S3 is primitive in
nature.The objects of the S3 class can be created simply by adding a class attribute to it.S3 classes support the
In S3 objects you can simply create a list.Consider the below example where a list is created with list elements
#Object Orientation in R
print(s3)
Output:
$name
[1] "Stephen"
$Standard
[1] "x"
A list s3 is created with name as “Stephen”, Standard as "x",age as 16 and location as " Canada”. These are the
attributes of the list s3 .The screenshot below helps you to understand about the attributes better, which shows
Once after creating the S3 list ie the list created with attributes name, standard, age, location you can convert
print(class(s3))
Output:
[1] "student"
2. S4 Classes
S4 classes are an improvement over S3 classes.S4 classes have a formally defined structure which helps in
making objects of the same class which look more or less similar.S4 class is more standardized and structured
An s4 class is defined using the setClass() function. In the below example the code defines s4 class with class
name “student” and slots are defined as a list where attributes name, standard, location are character, and age
is numeric.
setClass "student",slots=list(name="character",standard="character",age="numeric",locati))
After creating or defining a S4 class a specific instance of object is created using new().In the below code s4 is
an object created using new() where class name is student with slots like name,standard,age,location filled with
s = new("student",name="Sen",standard="XI",age=17,locati)
The whole program when executed returns the below output that shows an object created of class student and
slots with their values like “name” is “Sen “ , Slot "standard" is “XI”etc
#Object Orientation in R
Output:
Slot "name":
[1] "Sen"
Slot "standard":
[1] "XI"
Slot "age":
[1] 17
Slot "location":
[1] "UK"
To check an object is s4 you can use iss4() function.The iss4() functions returns a boolean value either TRUE if
the object is s4 else returns a FALSE which indicates the objects created is not s4 class.Let us check the object
IsS4(s4)
The code once executed returns a TRUE as result because it belongs to s4 class.
isS4(s3)
[1] FALSE
The @ symbol can be used to access the components or contents within s4 .The object type s4 followed by @
symbol and name of the component to be accessed.In below example “name” is one of the attribute created
s4@name
The @ symbol is also useful to set or reset or assign a value to the object.Let us reset the name “Sen” to
An object of class student with new name instead of “Sen” replaced with “Peter” is created as shown below.
Slot "name":
[1] "Peter"
Slot "standard":
[1] "XI"
Slot "age":
[1] 17
Slot "location":
[1] "UK"
The slot() function allows modifying the slots. The slot() function consists of the name of the object and
slot(s4,"name")
The code returns “Peter ” as output.You can also modify the value of object using slot() function.
slot(s4,"name")="john"
Output:
Slot "name":
[1] "john"
Slot "standard":
[1] "XI"
Slot "age":
[1] 17
while reference class is defined using setRefClass() The variable members of a class need to be included in
the class definition. In the Reference class, the member variables are called as fields like slots in the s4
class.
The below example defines the Reference class student with fields
setRefClass "student",fields=list(name="character",standard="character",age="numeric",locati
A generator function is returned by setRefclass() which is used to create new objects. The definition is stored
to a variable Student. The Student variable which has the definition forms the generator function for the class
student.
Student =
setRefClass("student",fields=list(name="character",standard="character",age="numeric",locati
print(Student)
forms a generator function for class student. It provides details such as class fields,class Methods.
Class fields:
Class Methods:
"field", "trace", "getRefClass", "initFields", "copy", "callSuper", ".objectPackage",
"export", "untrace",
"getClass", "show", "usingMethods", ".objectParent", "import"
Reference Superclasses:
"envRefClass"
The generator function is student() which creates new object with values to the fields.
Output:-
Reference class object of class "student"
Field "name":
[1] "John"
[1] "X"
[1] 15
[1] "UK"
> s$name
[1] "John"
> s$age
[1] 15
> s$ location
[1] "UK"
Field "name":
[1] "Paul"
[1] "X"
[1] 15
[1] "UK"
S3 class S4 class Reference class
Objects are created by Objects are created Objects are created using a generator
setting the class attribute. using new() function that stores class defined.
Attributes are accessed Attributes are accessed Attributes are accessed using $
using $ using @
Error handling is a crucial aspect of programming that allows to identify, and gracefully manage
errors or exceptions that may occur during the execution of code. In R Programming Language,
effective error handling can enhance the reliability of scripts and applications.
What are Errors in R?
An error refers to a condition that occurs when the execution of a statement or function encounters
a problem that prevents it from completing successfully. Good error handling helps to deal with
errors and gives helpful messages to users.
Error Handling Techniques
There are some different ways to handle errors in R programming
1. Try-Catch Blocks
2. Custom Error Handling
3. Stop Function
4. Finally Block (Cleanup)
5. The warning() function
1. Using tryCatch()
R
tryCatch({
result <- sqrt(-4)
print(result)
}, error = function(e) {
print("An error occurred:", e$message)
})
Output:
[1] NaN
Warning message:
In sqrt(-4) : NaNs produced
The code attempts to calculate the square root of -4, which is not possible in standard real number
arithmetic, resulting in a NaN (Not a Number) value.
Since an error occurred (trying to take the square root of a negative number), the error message
“An error occurred:” along with the specific error message is printed.
Additionally, a warning message is displayed indicating that NaNs (Not a Number) were
produced during the computation.
2.Custom Error Handling
R
check_positive <- function(val) {
if (val < 0) {
stop("Value must be positive")
}
return(val^2) # Squaring the positive value
}
tryCatch({
result <- check_positive(-7)
print(result)
}, error = function(e) {
print(paste("Error occurred:", e$message))
})
Output:
[1] "Error occurred: Value must be positive"
In the tryCatch block, we attempt to execute the check_positive function with a negative value. If
an error occurs within the try block (in this case, because the value is negative), the code jumps to
the error block where we specify what action to take in response to the error. Next print a custom
error message concatenated with the error message obtained from the caught error.
3.Stop Function
R
# Define a function to calculate the factorial of a non-negative integer
factorial <- function(n) {
if (n < 0) {
stop("Input must be a non-negative integer") # Stop execution if input is negative
}
if (n == 0) {
return(1) # Return 1 for factorial of 0
}
result <- 1
for (i in 1:n) {
result <- result * i # Calculate factorial
}
return(result)
}
# Example usage
result <- safe_division(10, 0)
print(result) # This will print "Error: Division by zero occurred."
Output:
[1] "Error: Division by zero occurred."
Logical Error
R
# Logical Error Example
# This code attempts to add two strings together, resulting in a logical error
# Corrected: Using paste() function to concatenate strings
result <- paste("Hello", "World")
print(result)
Output:
[1] "Hello World"
# Applying tryCatch
tryCatch(
# Specifying expression
expr = {
1 + 1
},
error = function(e){
},
warning = function(w){
print("There was a warning message.")
},
finally = {
print("finally Executed")
Output:
[1] "Everything was fine."
[1] "finally Executed"
withCallingHandlers() in R
In R, withCallingHandlers() is a variant of tryCatch(). The only
difference is tryCatch() deals with exiting handlers while
withCallingHandlers() deals with local handlers.
Example:
R
# Evaluation of tryCatch
withCallingHandlers(expression,
warning = function(w){
message("warning:\n", w)
},
error = function(e){
message("error:\n", e)
},
finally = {
message("Completed")
})
check({10/2})
check({10/0})
check({10/'noe'})
Output:
R Packages
R packages are the collection of R functions, sample data, and compile codes. In the R environment, these
packages are stored under a directory called "library." During installation, R installs a set of packages. We can
add packages later when they are needed for some specific purpose. Only the default packages will be
available when we start the R console. Other packages which are already installed will be loaded explicitly to be
used by the R program.
There is the following list of commands to be used to check, verify, and use the R packages.
Check Available R Packages
To check the available R Packages, we have to find the library location in which R packages are contained. R
provides libPaths() function to find the library locations.
1. libPaths()
When the above code executes, it produces the following project, which may vary depending on the local
settings of our PCs & Laptops.
ADVERTISEMENT
[1] "C:/Users/ajeet/OneDrive/Documents/R/win-library/3.6"
[2] "C:/Program Files/R/R-3.6.1/library"
R provides library() function, which allows us to get the list of all the installed packages.
1. library()
When we execute the above function, it produces the following result, which may vary depending on the local
settings of our PCs or laptops.
1. search()
When we execute the above code, it will produce the following result, which may vary depending on the local
settings of our PCs and laptops:
In R, there are two techniques to add new R packages. The first technique is installing package directly from
the CRAN directory, and the second one is to install it manually after downloading the package to our local
system.
ADVERTISEMENT
The following command is used to get the packages directly from CRAN webpage and install the package in the
R environment. We may be prompted to choose the nearest mirror. Choose the one appropriate to our location.
1. install.packages("Package Name")
Output
Once the downloading has finished, we will use the following command:
List of R packages
R is the language of data science which includes a vast repository of
packages. These packages appeal to different regions which use R for
their data purposes. CRAN has 10,000 packages, making it an ocean of
superlative statistical work. There are lots of packages in R, but we will
discuss the important one.
There are some mostly used and popular packages which are as follows:
1) tidyr
The word tidyr comes from the word tidy, which means clear. So
the tidyr package is used to make the data' tidy'. This package works well
with dplyr. This package is an evolution of the reshape2 package.
2) ggplot2
R allows us to create graphics declaratively. R provides
the ggplot package for this purpose. This package is famous for its
elegant and quality graphs which sets it apart from other visualization
packages.
3) ggraph
R provides an extension of ggplot known as ggraph. The limitation
of ggplot is the dependency on tabular data is taken away in ggraph.
4) dplyr
R allows us to perform data wrangling and data analysis. R provides
the dplyr library for this purpose. This library facilitates several functions
for the data frame in R.
5) tidyquant
The tidyquant is a financial package which is used for carrying out
quantitative financial analysis. This package adds to
the tidyverse universe as a financial package which is used for importing,
analyzing and visualizing the data.
6) dygraphs
The dygraphs package provides an interface to the main JavaScript library
which we can use for charting. This package is essentially used for
plotting time-series data in R.
7) leaflet
For creating interactive visualization, R provides the leaflet package. This
package is an open-source JavaScript library. The world's popular websites
like the New York Times, Github and Flicker, etc. are using leaflet. The
leaflet package makes it easier to interact with these sites.
8) ggmap
For delineating spatial visualization, the ggmap package is used. It is a
mapping package which consists of various tools for geolocating and
routing.
ADVERTISEMENT
9) glue
R provides the glue package to perform the operations of data wrangling.
This package is used for evaluating R expressions which are present
within the string.
10) shiny
R allows us to develop interactive and aesthetically pleasing web apps by
providing a shiny package. This package provides various extensions with
HTML widgets, CSS, and JavaScript.
11) plotly
The plotly package provides online interactive and quality graphs. This
package extends upon the JavaScript library -plotly.js.
12) tidytext
The tidytext package provides various functions of text mining for word
processing and carrying out analysis through ggplot, dplyr, and other
miscellaneous tools.
13) stringr
The stringr package provides simplicity and consistency to use wrappers
for the 'stringi' package. The stringi package facilitates common string
operations.
14) reshape2
This package facilitates flexible reorganization and aggregation of data
using melt () and decast () functions.
15) dichromat
The R dichromat package is used to remove Red-Green or Blue-Green
contrasts from the colors.
16) digest
The digest package is used for the creation of cryptographic hash objects
of R functions.
17) MASS
The MASS package provides a large number of statistical functions. It
provides datasets that are in conjunction with the book "Modern Applied
Statistics with S."
18) caret
R allows us to perform classification and regression tasks by providing the
caret package. CaretEnsemble is a feature of caret which is used for the
combination of different models.
19) e1071
The e1071 library provides useful functions which are essential for data
analysis like Naive Bayes, Fourier Transforms, SVMs, Clustering, and other
miscellaneous functions.
20) sentimentr
The sentiment package provides functions for carrying out sentiment
analysis. It is used to calculate text polarity at the sentence level and to
perform aggregation by rows or grouping variables.