Get Help And Discuss STEM Concepts From Math To Data Science & Financial Literacy
STEM Gender Equality | Join us on ZOOM | Spreading Mathematical Happiness

Help The Education Support Forum through MathsGee serve learners across Africa with a DONATION

1 like 0 dislike
217 views

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



in Data Science by Diamond (48,972 points) | 217 views

1 Answer

0 like 0 dislike
Best answer

According to the documentation for both functions (accessed by putting a ? before the function name and hitting enter), require is used inside functions, as it outputs a warning and continues if the package is not found, whereas library will throw an error.

library(package) and require(package) both load the package with name package and put it on the search list. require is designed for use inside other functions; it returns FALSE and gives a warning (rather than an error as library() does by default) if the package does not exist. Both functions check and update the list of currently loaded packages and do not reload a package which is already loaded. (If you want to reload such a package, call detach(unload = TRUE) or unloadNamespace first.) If you want to load a package without putting it on the search list, use requireNamespace.

 

by Diamond (48,972 points)

Related questions

0 like 0 dislike
1 answer
asked Mar 11, 2019 in Data Science by Edzai Zvobwo Bronze Status (8,427 points) | 18 views
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
0 answers

Welcome to MathsGee Q&A Bank, Africa’s largest personalized STEM and Financial Literacy education network that helps people find answers to problems, connect with others and take action to improve their outcomes.


MathsGee Q&A is the STEM and Financial Literacy knowledge-sharing community where students and experts put their heads together to crack their toughest questions.


Help The Education Support Forum through MathsGee serve learners across Africa with a DONATION

Enter your email address: