What is the difference between library () and require () functions in R ?

0 votes
I do not understand the difference between two of these. Please help someone.
Sep 5, 2018 in Data Analytics by shams
• 3,630 points
470 views

1 answer to this question.

0 votes
 library() require()
  • Library () function gives an error message display, if the desired package cannot be loaded.
  • Require () function is used inside function and throws a warning messages whenever a particular package is not Found
  • It loads the packages whether it is already loaded or not,
  • It just checks that it is loaded, or loads it if it isn’t (use in functions that rely on a certain package). The documentation explicitly states that neither function will reload an already loaded package.

Consider a related program for the above differentiation.

if(!require(package, character.only=T, quietly=T)) {

install.packages (package)

library(package, character.only=T)

}

For multiple packages you can use

for(package in c(”, ”)) {

if(!require(package, character.only=T, quietly=T)) {

install.packages (package)

library(package, character.only=T)

}

}

answered Sep 5, 2018 by zombie
• 3,750 points

Related Questions In Data Analytics

0 votes
1 answer
0 votes
2 answers

What is the difference between %% and % in R programming?

HI, %% returns remainder in case of numeric ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 32,490 points
303 views
0 votes
1 answer

What is the difference between list and vector in R?

The difference are - A list holds different ...READ MORE

answered Oct 28, 2019 in Data Analytics by Cherukuri
• 32,490 points
9,177 views
0 votes
1 answer

What is the difference between merge and bind in R?

Merge function merges an arbitrarily large series ...READ MORE

answered Oct 28, 2019 in Data Analytics by Cherukuri
• 32,490 points
1,068 views
0 votes
1 answer

What is the difference between R and SPSS?

One of the main difference is R ...READ MORE

answered Dec 11, 2018 in Data Analytics by Maverick
• 10,820 points
317 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is "size" includes NaN values, ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8 by Gitika 1,143 views
+1 vote
2 answers

What is the difference between correlation and covariance?

Correlation and Co-variance both are used as ...READ MORE

answered Jul 24, 2018 in Data Analytics by Abhi
• 3,680 points
2,143 views
0 votes
1 answer

What is the difference between random forest and decision trees?

The basic difference is that Random Forest ...READ MORE

answered Jul 30, 2018 in Data Analytics by Abhi
• 3,680 points
1,045 views
0 votes
1 answer

What is the difference between rnorm and runif functions ?

rnorm function generates "n" normal random numbers ...READ MORE

answered Oct 10, 2018 in Data Analytics by zombie
• 3,750 points
368 views
0 votes
1 answer

How to find out the package version which is loaded in R?

You can use sessionInfo() to accomplish that. > ...READ MORE

answered Apr 18, 2018 in Data Analytics by zombie
• 3,750 points
76 views