Skip to content

Instantly share code, notes, and snippets.

@disulfidebond
Last active December 3, 2019 18:23
Show Gist options
  • Save disulfidebond/2dca7108eac56dd2c8bca6578d905cfd to your computer and use it in GitHub Desktop.
Save disulfidebond/2dca7108eac56dd2c8bca6578d905cfd to your computer and use it in GitHub Desktop.
R Setup Mac OSX

Overview

This writeup describes how to setup R on Mac OSX. The steps below are not numbered, but should be completed in sequential order.

Check to see if Xcode Commandline tools are installed:

  1. Open the Terminal.app application, either by searching for it via Spotlight or in the /Applications folder

  2. Type git in the window that opens, and press return.

  3. If you see the following output, git and commandline tools are installed:

     usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
        [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
        [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
        [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
        <command> [<args>]
     
     These are common Git commands used in various situations:
     
     start a working area (see also: git help tutorial)
       clone      Clone a repository into a new directory
       init       Create an empty Git repository or reinitialize an existing one
     
     work on the current change (see also: git help everyday)
       add        Add file contents to the index
       mv         Move or rename a file, a directory, or a symlink
       reset      Reset current HEAD to the specified state
       rm         Remove files from the working tree and from the index
     
     examine the history and state (see also: git help revisions)
       bisect     Use binary search to find the commit that introduced a bug
       grep       Print lines matching a pattern
       log        Show commit logs
       show       Show various types of objects
       status     Show the working tree status
     
     grow, mark and tweak your common history
       branch     List, create, or delete branches
       checkout    Switch branches or restore working tree files
       commit     Record changes to the repository
       diff       Show changes between commits, commit and working tree, etc
       merge      Join two or more development histories together
       rebase     Reapply commits on top of another base tip
       tag        Create, list, delete or verify a tag object signed with GPG
     
     collaborate (see also: git help workflows)
       fetch      Download objects and refs from another repository
       pull       Fetch from and integrate with another repository or a local branch
       push       Update remote refs along with associated objects
     
     'git help -a' and 'git help -g' list available subcommands and some
     concept guides. See 'git help <command>' or 'git help <concept>'
     to read about a specific subcommand or concept.`
    

If you see a popup window notifying you that commandline tools needs to be installed, click 'OK' to install commandline tools.

Be patient, the installation may take awhile. Once it is finished, the window will indicate that installation was complete.

Check to see if R is installed

  1. Open the Terminal.app application, either by searching for it via Spotlight or in the /Applications folder
  2. Type r in the window that opens, and press return.

In the resulting output, if you see something similar to the following, R has been installed:

  R version 3.2.0 (2015-04-16) -- "Full of Ingredients"

If you receive the error '-bash: r: command not found', then R has not been installed.

If R has not been installed

Note 1: R Studio requires R to be installed; if R has not been installed and you see R Studio, then R Studio was installed incorrectly.

Broadly speaking, there are two ways to install R, depending on if you have homebrew installed or not.

Note 2: It is beyond the scope of this writeup to explain the benefits and disadvantages of using homebrew, however, it is a fairly safe and useful package manager to install.

If you have homebrew installed

  1. Open Terminal.app or a Terminal.app window.
  2. Type brew update then press the return key. Be patient, this step may take awhile.
  3. Type brew install R then press the return key. Be patient, this step may take awhile.

If you do not have homebrew installed

Navigate to https://www.r-project.org and download the latest (or most appropriate) version of R. Follow the prompts in the installer to complete the installation.

If R has been installed but not R Studio

  1. Navigate to the R Studio download site and select the version of R that matches your computer, for example, macOS 10.12+ (64-bit) is the version for Mac OSX.

  2. Click the download link, then either run the installer, or perform the optional checking step and then run the installer.

  3. Open a new window in Terminal.app, copy and paste the folowing command, then press the return key:

      ARR=($(r --version | cut -d\  -f3 | cut -d.  -f1)) ; export RVERSION="${ARR[0]}" ; mkdir -p ${HOME}/Documents/Library/R/${RVERSION}/library
    
  4. R Studio should be successfully installed.

Note 1: It is a very good idea to create a personal library for packages that R uses, which Step 3 above does for you.

Optional Checking Step

This step is optional, but highly recommended.

  1. Download the RStudio file as previously described.

  2. The download page for RStudio should have a table with Installer, Size, Date, and MD5 columns. Copy the text with letters and numbers from the MD5 column that is on the same row as the installer that you clicked to download R Studio.

  3. Open Terminal.app, or if already open, open a new Terminal window prompt by pressing Command-N

  4. Type the following into the Terminal window (do not press return yet):

     V1=
    
  5. Paste the text that you copied from step 3 into this terminal window, then press the return key.

  6. In the same Terminal window, copy and paste the following text (do not press return yet):

     FNAME=
    
  7. Next, locate the downloaded R Studio installer file on your hard drive, and click and drag it to the same Terminal window that you just opened and copied/pasted text into. Once you have done this, press the return key.

  8. Copy and paste this line of code into the same Terminal window:

     export V1=$(md5 $FNAME | cut -d\  -f4) ; if [[ $V1 != $V2 ]] ; then echo 'Warning, there is a problem with the file!' ; else echo 'The file passed the verification step, you are good to go!' ; fi
    
  9. If you see the text 'The file passed the verification step, you are good to go!', then everything is ok. Otherwise, you need to check the downloaded installer for corruption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment