TEDSF Interview Skills Q&A Platform
1 like 0 dislike
113 views

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



in Data Science by Platinum (104k points) | 113 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 Platinum (104k points)

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
0 answers
asked Mar 11, 2019 in Data Science by Edzai Zvobwo Platinum (55.1k points) | 9 views
0 like 0 dislike
0 answers
0 like 0 dislike
0 answers
Welcome to TEDSF Skills Questions and Answers, a platform, where you can ask skills questions and receive answers from other members of the community. On TEDSF the youth, students, teachers, policy makers and enthusiasts can ask and answer any questions. Get help and answers to any skills-related problem including mathematics, computer science, data science, web development, physics, chemistry, digital marketing, African development and more. Help is always 100% free!

4.1k questions

1.4k answers

64 comments

29.6k users

4,058 questions
1,448 answers
64 comments
29,583 users