RStudio

Installing R and RStudio

R and RStudio are both free, open-source software, available for all commonly used operating systems, including Windows, Mac OS X, and Linux systems. R and RStudio install in the standard manner on each of these systems. System-specific instructions for installing R are given below. Regardless of your operating system, you should install R before installing RStudio.

If you wish to install the R Commander graphical user interface for R (not used in this short course), please consult the R Commander installation instructions.

Please read and follow these instructions carefully. Installation assistance will also be availabile in the help sessions.

Installing R on Windows

bulletVisit the Comprehensive R Archive Network (CRAN) and select a mirror site; a list of CRAN mirrors appears at the upper left of the CRAN home page. I suggest that you use the 0-Cloud RStudio mirror, which is the first on the list. Click on the link Download R for Windows, which appears near the top of the page; then click on install R for the first time, and subsequently on Download R 3.2.3 for Windows (or whatever is the current version of R). Once it is downloaded, double-click on the R installer. You may take all of the defaults, but I suggest that you make the following modifications:

bulletInstead of installing R in the standard location, C:\Program Files\R\R-3.2.3, I suggest that you use C:\R\R-3.2.3. This will allow you to install packages without running R with administrator privileges and will avoid problems that sometimes occur when there are spaces in paths.

bulletIn the Startup options screen, I suggest that you select Yes (customized startup). Then select the SDI (single-document interface) in preference to the default MDI (multiple-document interface); feel free to make other changes, but you may take all the remaining defaults.

Building Packages Under Windows, etc. (Optional)

bulletIf you wish to build packages, or use compiled C, C++, or Fortran code in R, you will have to install some additional software and properly configure your Windows system. You do not have to be able to build R packages in order to install pre-built Windows binary packages from CRAN, so these steps are generally unnecessary unless you plan to write your own packages or use compiled code.

bulletClick on the Rtools link on the R for Windows CRAN page. Download the current version of the Rtools installer and run it. You may take all of the other defaults, but do allow the Rtools installer to modify your system path, by checking the box to edit the system path. If you want to be able to build R packages outside of RStudio, add c:\R\R-3.2.3\bin; to the path (assuming that you installed R in the location that I suggested), after the items added by the Rtools installer (i.e., after c:\Rtools\gcc-4.6.3\bin). Type this location carefully, including the terminating semicolon -- you don't want to mess up your path.

bulletIf you want to be able to build PDF help files for packages, download and install the MiKTeX LaTeX system; there is also a link to MiKTeX on the Building R for Windows page. Installing MiKTeX will also allow you to create Sweave and knitr LaTeX documents in RStudio, and to compile R Markdown documents directly to PDF files.

Installing R on Mac OS X

bulletVisit the Comprehensive R Archive Network (CRAN) and select a mirror site; a list of CRAN mirrors appears at the upper left of the CRAN home page. I suggest that you use the 0-Cloud RStudio mirror, which is the first on the list. Click on the link Download R for MacOS X, which appears near the top of the page; then click on R-3.2.3.pkg (or whatever is the current version of R), which assumes that you are using Mac OS X 10.9 (Mavericks) or higher. You'll also find an older version of R if you have an older version of Mac OS X (10.6, Snow Leopard, or higher). Once it is downloaded, double-click on the R installer. You may take all of the defaults.

Building Packages Under Mac OS X, etc. (Optional)

bulletIf you wish to build packages (a topic not covered in the lecture series), or use compiled C, C++, or Fortran code in R, you must install the Apple Xcode developer tools. For Mac OS X 10.7 (Lion), 10.8 (Mountain Lion), or 10.9 (Mavericks), you can install Xcode for free from the App Store. For earlier versions of Mac OS X, Xcode can be installed from your system DVD or downloaded from the Apple developer website. You do not need Xcode to install pre-built Mac OS X binary packages from CRAN, so this step is unnecessary unless you plan to write your own packages or use compiled code.

bulletSome R packages include Fortran code; to build such packages, you will have to install a Fortran compiler. You do not need the Fortran compiler to build most packages, nor to install pre-built Mac OS X binary packages from CRAN. Click on the tools link on the R for Mac OS X page, and click on the link for gfortran-4.2.3.dmg. Double-click on this file once the download is complete; and then double-click on the installer, gfortran.pkg. Complete the installation.

bulletIf you want to be able to build PDF help files, download and install the MacTeX LaTeX system. Installing MacTeX will also allow you to create Sweave and knitr LaTeX documents in RStudio, and to compile R Markdown documents directly to PDF files.

Installing X-Windows on Mac OS X(Optional)

bulletSome R software (e.g., my Rcmdr package) makes use of the Tcl/Tk graphical-user-interface (GUI) builder via the tcltk package to create point-and-click interfaces and to display GUI elements such as progress bars. To use the tcltk package, which is a standard part of the R distribution, you must have the X11 windowing system installed on your Mac.

bulletCheck to see whether the X11 windowing system (X Windows) has already been installed on your computer:

For OS X 10.6 and 10.7, the file X11.app should appear in the Utilities folder under Applications in the finder. This application should always be installed under OS X 10.7.

For OS X 10.8 or higher, the file is named XQuartz.app and is no longer included with the operating system. XQuartz.app may also be installed in OS X 10.6 or 10.7.

Note that if you upgrade OS X, you will have to reinstall XQuartz even if you installed it previously.

You may also issue the command capabilities("X11") at the R command prompt. If the response is TRUE then X11 is installed.

bulletIf neither X11.app nor XQuartz.app is installed, install XQuartz from http://xquartz.macosforge.org:

Installing R on Linux Systems

bulletVisit the Comprehensive R Archive Network (CRAN) and select a mirror site; a list of CRAN mirrors appears at the upper left of the CRAN home page. I suggest that you use the 0-Cloud RStudio mirror. Click on the link Download R for Linux, which appears near the top of the page. R is available for several Linux distributions (Debian, RedHat, SUSE, and Ubuntu); select your distribution, and proceed as directed.

bulletIf you have a Linux or Unix system that's not compatible with one of these distributions, you will have to compile R from source code; the procedure for doing so is is described in the R FAQ (frequently asked questions) list.

Installing RStudio

bulletGo to the RStudio download page and download the appropriate installer for your operating system (Windows, Mac OS X, or Linux). Visit the RStudio home page for more information about RStudio.

bulletOnce it is downloaded, run the RStudio installer and take all of the defaults: In Windows, double-click on the RStudio installer to start the installation; in Mac OS X, double-click on the downloaded RStudio disk-image file, and drag the RStudio icon to the Applications folder.

bulletWhen you first run RStudio, it should detect your R installation and start the R 3.2.3 console. To configure RStudio to your taste, select Tools > Global Options (Windows) or RStudio > Preferences (Mac OS X) from the RStudio menus. In particular, I suggest that on the General options screen you deselect Restore .RData into workspace at startup, and set Save workspace to .RData on exit to Never. If you encounter difficulties, consult the RStudio troubleshooting guide.

Installing R Packages for the Seminars

bulletOnce you have installed R and RStudio, you can install additional packages required for the seminars by typing the following command at the > command prompt in the R Console (and pressing the Enter or return key).

For the structural-equation modeling sessions:

install.packages(c("car", "MBES", "polycor", "sem"))

For the discussion of package-building:

install.packages(c("car", "devtools", "knitr", "rmarkdown"))

To use the R Commander (Mac users, see the instructions above for installing X-Windows):

install.packages("Rcmdr")

You can also consult more detailed instructions about installing the R Commander.

You can simply copy and paste these commands from the installation instructions. Alternatively, you can install packages from the RStudio Packages tab.

Finally, if you want to try using C++ code within R, also install the Rcpp package.