NOOB question... sorry

Hey folks... so like many noobs, lets start with "sorry for the lame question". I am doing the google Data Analyst course and have a very rudimentary background in script and coding so again... sorry.

I have not seen it anywhere so it must be purely fundamental but... Could someone confirm for me, do we need to load the library for each script in request.

For example: If I am working in concept with ggplot2, do I need to start the script area with first changing to that library? I tried to create a script start with packages and libraries to ensure that everything is loaded but then ggplot2 does not work unless I first use the library(ggplot2) script before. Hope that you all understand my question.

This is what I did...
....
install and refresh packages for project.
install.packages("palmerpenguins")
library(palmerpenguins)
install.packages("ggplot2")
library(ggplot2)
install.packages("tidyverse")
library(tidyverse)
install.packages("lubridate")
library(lubridate)
install.packages("readr")
library(readr)
install.packages("skimr")
library(skimr)
install.packages("janitor")
library(janitor)
install.packages("dplyr")
library(dplyr)

Class code goes here

library(palmerpenguins)
data(penguins)
View(penguins)
library(ggplot2)
ggplot(data = penguins) + geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))
....

Cheers

You generally only need to install.packages once. R will remember that you have installed it. You need to do library once in each session, so putting it at the top of a script--as you've done--is a good idea.

Thanks for the quick reply... good to know

Hi @Ron_Hayes , welcome!

For example next when you run install.packages("palmerpenguins") you could add # for comment this line of a script and avoid run again.

Like this:

# Run the first time and install.
install.packages("palmerpenguins")
library(palmerpenguins)

# Run next day, only load the library:
# install.packages("palmerpenguins")
library(palmerpenguins)

Other way is it:

# INSTALL LIBRARIES -------------------------------------------------------
install.packages("palmerpenguins")
install.packages("ggplot2")
install.packages("tidyverse")
install.packages("lubridate")
install.packages("readr")
install.packages("skimr")
install.packages("janitor")
install.packages("dplyr")
#-----

# LOAD LIBRARIES ----------------------------------------------------------
library(palmerpenguins)
library(ggplot2)
library(tidyverse)
library(lubridate)
library(readr)
library(skimr)
library(dplyr)