3 Installation

3.1 Installing R

To install R, you need to:

  • Go to The Comprehensive R Archive Network (CRAN)
  • Select the closest mirror to you (e.g., in Japan, https://cran.ism.ac.jp/)
  • Select a precompiled binary distribution according to your OS
  • Download the latest installer (at writing time, R-3.5.1—“Feather Spray”)
  • Open the installer and follow its instructions
  • There is a GUI for R called RStudio, although popular, I don’t find it particularly advantageous.

3.2 Internationalization issues in Mac OS

For those in Mac OS:

R is capable of displaying GUI elements and messages in the language that is set as default by the operative system. Sometimes, this causes problems with scripts (e.g., unable to correctly display non-alphanumeric characters). If you get a message similar to this one in the R console:

During startup - Warning messages: 
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_PAPER failed, using "C"
[R.app GUI 1.50 (6126) x86_64-apple-darwin9.8.0]
WARNING: You're using a non-UTF8 locale, therefore only ASCII characters will 
work. Please read R for Mac OS X FAQ (see Help) section 9 and adjust your 
system preferences accordingly. [History restored from /Users/nemo/.Rapp.history]

Do this:

  1. Write or paste in the R console:
system("defaults write org.R-project.R force.LANG en_US.UTF-8")
  1. Restart R

Note: There is an error in the WARNING message. Section 7 (instead of section 9) is the actual section of the Mac OS X FAQ where this issue is explained.

3.3 Installing packages (libraries)

  1. Launch the ‘R Package Installer’ from the Menu ‘Packages & Data’ > Package Installer
    Interface to search and install libraries.

    Figure 3.1: Interface to search and install libraries.

  2. In the search box, type the name of the desired package (e.g., ez)
  3. Check the “Install Dependencies” box
  4. Select the closest mirror to you (only the first time)
    Interface to select a desired mirror CRAN site.

    Figure 3.2: Interface to select a desired mirror CRAN site.

  5. Set it as default mirror by pressing the “Yes” button
  6. Select the desired library from the list and press “Install Selected”

Let’s practice:

Install the following packages:

  • ggplot2
  • ez
  • plyr

3.4 Updating libraries

It is a good idea to update your installed libraries to their latest version. This can be done by clicking in the “Update All” button in the “R package Installer” window shown in Figure 3.1.