How to Use R on Mac

Learn how to use R on Mac machine.

To use R on a Mac machine, we have to first install R for Mac, as noted in the installation section. Once R is installed, running it on Mac requires only slight modifications to the R code for Windows. The most obvious difference is how to refer to the path to a file.

To illustrate the difference, we may first create a Project folder on the Mac desktop by clicking on the NewFolder option under File on the upper left corner of the home screen. Then to obtain the path for the Project folder, we first click on the folder, then click File on the upper left corner of the screen, next click the GetInfo option, and then copy the path right after where: in the Project info page for our R program. Now take our first toy program for Windows as an example. All we need to modify in that program for Mac is to replace the Windows path with the Mac path, as follows:

# First R practice program, July 2016, R version 3.2.3 # show current working directory path
getwd()
# change working directory for program to project folder # first copy the path from getinfo
# and then add the project folder name setwd("/Users/quanli/Desktop/Project")
 # show current working directory path again to verify
getwd()   

Get hands-on with 1200+ tech skills courses.