Difference between install.packages() and library()

Viewed 78

Per my understanding, ggplot2 is part of the tidyverse package. If, after installing tidyverse, I load it through library(), then do I need to also load individual packages such as ggplot2 as well?

I've seen my Coursera instructor load the entire tidyverse and sometimes just individual packages.

Also, I noticed some arguments need to be enclosed in quotes while others do not. For example, install.packages() needs "", but library() doesn't.

Is there a list which shows which arguments need to be enclose in quotation marks that I can refer to?

1 Answers

The tidyverse is an overarching package which includes ggplot2 along with many others like dplyr and tidyr. Depending on what you're trying to do, you may attach either all or only a small subset of the tidyverse packages.

If you've already loaded in tidyverse, yes, ggplot2 would be redundant. It's good practice to only load in packages you're actually going to use because there's the possibility of multiple packages having identically named functions that would require you to preface them with <package_name>:: to distinguish them.

install.packages() requires quotes for the library in question, library() does not.

Related