Installing R packages with Internet Access in Your Project

In this lab, you will install the R package gapminder. The name of the package you will need to install for different labs may change.

General Goals

In this lab, you will learn the following:

  • How to install R packages in Cocal with a paid server.

Installing R packages

Do the following steps:

  1. Go to your Home directory.
  2. Create a Linux Terminal file in your project or open one that is already in your project.
  3. When the prompt appears (~$), type an upper-case letter R and press the Return Key. This will start up R.
  4. Type install.packages("gapminder")

The following will be displayed:

Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages("gapminder") :
  'lib = "/usr/local/lib/R/site-library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) 
  1. Type yes.
The following will be displayed:
Would you like to create a personal library
‘~/R/x86_64-pc-linux-gnu-library/4.1’
to install packages into? (yes/No/cancel)
  1. Type yes again.

The following will be displayed:

trying URL 'https://cloud.r-project.org/src/contrib/gapminder_0.3.0.tar.gz'
Content type 'application/x-gzip' length 2110951 bytes (2.0 MB)
==================================================
downloaded 2.0 MB

* installing *source* package ‘gapminder’ ...
** package ‘gapminder’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (gapminder)

This means that the package gapminder is installed in your project.

  1. (Optional) If you type in the command: .libPaths()

Then something similar to the following will be displayed:

[1] "/home/user/R/x86_64-pc-linux-gnu-library/4.1"
[2] "/usr/local/lib/R/site-library"               
[3] "/usr/lib/R/site-library"                     
[4] "/usr/lib/R/library"                          
>

Note: You can see that the library directory was created and appears in line [1].

Next time you install another package in your project’s Home directory, you will not need to create the library because it has already been created (you will NOT run steps 5 and 6).