9) Load and Unload Packages in RStudio.

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

When a package is installed it is not by default available for use, to save memory and resources.  Loading a package in RStudio is an extremely simple toggle process which will send the command to console to load a specific package on select,  unload on deselect.

Loading a package uses the library() function, invoked before a script is run.

Navigate to the packages pane in the bottom right hand corner of the RStudio, clicking on the tab if necessary.

ggplot2-in-the-rstudio-package-window.png

Note the package that was installed previously,  ggplot2, and the check box to the left hand side of the package name.  To load the package simply select the textbox via a click of the mouse:

toggle-loading-a-package-in-rstudio-r-console.png

On selection of the checkbox the library() function, complete with the required parameters, will be processed in the console.  It can also be observed that the location of the package has been specified in this function call,  although that is not strictly necessary.

To unload the package,  deselect the checkbox in the packages pane next to ggplot2:

toggle-unloading-package-in-rstudio-r-console.png

On deselection of the checkbox the detatch() function is sent to the console for the package (notice the string will match the return of the search() function).