Do you know about sessions? For example, did you run library(ggplot2)
earlier, close R Studio, then open it up again? Code run in a previous session won't be run when you start a new one.
This can be surprising, because R likes to push "workspace images" as a default behavior; when you exit a session, you may be asked, "Save workspace image?" This creates a file named .RData
in the working directory which stores all the objects in your session's environment. Whenever you start a new session in that directory, it will automatically load them. But it won't reload packages.
If you haven't already, I'd suggest disabling this behavior and the pop-up window. In RStudio, go to Tools > Global Options > General. Then uncheck "Restore .RData into workspace at startup" and set "Save workspace to .RData on exit" to "Never."

The best practice is to write scripts that can recreate the work each time. This reduces the chance of unpleasant surprises from leftover objects in the workspace. If you do need to save data (e.g. it takes half an hour to create a dataset), use the save()
and load()
functions in your script. That way, anyone reading it (including future you) will know what's going on.