10) Load Packages using Script.

This Blog entry is from the Getting Started in R section in Learn R.

While the toggle function is a useful feature of RStudio,  the intention is to maintain a script Active, Console Passive approach, henceforth it is important to ensure that the librarby() function call, to be streamed to the console is moved to the head of the script and that the detach() function is moved to the base of the script.

Start by navigating to the very top of the script and create a new line in the script editor. Navigate to the start of the first line and press the enter key:

adding-library-to-top-of-r-script.png

Invoking the library() function,  type:

library(ggplot2)
loading-ggplot2-using-library-function-in-r.png

Intelisense will look through the search path and suggest some packages,  and this can also be auto-completed to ggplot2.  Upon completion of the line,  run the script line to the console:

r-console-packag-loaded-ggplot2.png

The ggplot library is now loaded as the first line of the script.