How to Permanently Keep the Lubridate Argument

I just started to study R in Posit Studio and just learned the lubridate function. However, I know that the code to install it is:
install.packages("tidyverse")
library(tidyverse)
library(lubridate)
This works, and as a result I can type in commands like now() But if I end the session, the same R code doesn't work, and I have to redo the three-line code to allow, which becomes a bit repetitive and boring. How do I permanently install the lubridate function so I don't have to keep repeating the same commands every session?

assuming you have modern version of tidyverse as since march 2023 lubridate has become a core of the included packages. Teaching the tidyverse in 2023
going forward it would be sufficient for you only to do

library(tidyverse)

if you dont want to be bothered with having this in your scripts, or typing it into your fresh sessions. you can alter your .Rprofile file to include it.
the most convenient way to edit your .Rprofile is probably via the usethis packages edit_r_profile function as it takes care of finding that file and opening it for you.

hope this helps

Thanks for the first solution, it does work. However, Do you know the steps for the .Rprofile thing? Sorry, but I just started to learn it yesterday and I am unfamiliar with the usethis package and edit_r_profile function.

# Make sure that the tidyverse is always loaded 
# by adding it to the .Rprofile file with the 
# edit_r_profile() function form the usethis package

# install usethis if you haven't already
install.packages("usethis")

# read the documentation for the .Rprofile 
?.Rprofile

# open the .Rprofile file in the Source pane of RStudio
usethis::edit_r_profile()

# add this text to the .Rprofile
local({
  old <- getOption("defaultPackages")
  options(defaultPackages = c(old, "tidyverse"))
})

# save the file and restart R with Session > Restart R

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.