7) Browsing and Installing Packages.

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

For the purposes of these Blog entries all external packages will be sourced from CRAN via Rstudio.   In this Blog entry the graphics and plotting package titled ggplot2 will be installed.

Navigate to the Packages pane, clicking the tab if necessary, in the botton right hand corner of RStudio:

packages-window-in-rstudio.png

Click on the button Install:

packages-install-button-in-rstudio.png

The Install Package dialog box will display,  defaulting to the CRAN mirror:

cran-repository-in-rstudio-install-window.png

To search for a package by name, type the name in the package textbox:

ggplot2
automatically-finding-packages-from-cran-mirror.png

Autocomplete will suggest two packages having reviewed potential matched on CRAN,  accept \ click on the suggested ggplot2:

ggplot-install-package-in-rstudio.png

Always keep the Install Dependencies button as checked.  Clicking install will send commands to the console to install the packages:

ggplot-package-being-installed-to-console.png

The package is now installed. 

Executing the search() function it can be observed however that the package appears not to be loaded:

confirming-ggplot-package-has-been-installed-in-r-console.png

6) Identify Packages Installed.

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

Packages are a collection of files contained in the runtime directory of R. The runtime directory, where the packages are installed, is know as the search path.

To get a picture of the pakages installed start by setting focus in the script window by clicking in the pane in the top top left hand corner:

creating-a-new-script-in-rstudio.png

To view the physical location of the packages type:

searchpaths()
searchpaths-in-r-intelisense.png
searchpaths-in-r.png

Intelisense in Rstudio will suggest the function as the keystrokes take place.

Upon the function having been written in the script editor, move the cursor to the start of the line (it will be implicitly understood that this has taken place in future Blog entries when the instruction to Run to console is given):

clicking-run-line-in-rstudio-set-cursor-to-start.png

Click the Run button or achive the same via a Ctrl+Enter key combination:

clicking-run-line-in-r-studio.png

Run sends the line of script to the console for execution:

run-line-in-r-studio-has-written-to-console.png

 

Upon close inspection,  it can be seen that the packages and their file location in the R execution directory have been listed in the console:

[1] ".GlobalEnv"                                   "tools:rstudio"                              

 [3] "C:/Program Files/R/R-3.3.2/library/stats"     "C:/Program Files/R/R-3.3.2/library/graphics"

 [5] "C:/Program Files/R/R-3.3.2/library/grDevices" "C:/Program Files/R/R-3.3.2/library/utils"   

 [7] "C:/Program Files/R/R-3.3.2/library/datasets"  "C:/Program Files/R/R-3.3.2/library/methods" 

 [9] "Autoloads"                                    "C:/PROGRA~1/R/R-33~1.2/library/base"  

A more environment focussed presentation of the pakages can be archived by creating a new line in the script editor and typing:

search()
search-in-r.png

Run to console:

search-has-written-to-r-console.png

The search() function gives a more concise list of the packages that are available and loaded.