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)
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.
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)