Running R on macOS provides users with powerful statistical computing and graphics capabilities. Whether you prefer the command-line interface in Terminal.app or the user-friendly GUI in R.app, macOS offers flexibility in how you interact with R. In this guide, we'll explore both methods of invoking R on your Mac.
Running R in Terminal.app
Accessing R in the Terminal
- Open Terminal.app: You can find it in the Applications/Utilities folder or search for it using Spotlight.
- Type `R` and press Enter: This command launches the R interpreter in the Terminal window.
Command-line Arguments
Unlike some UNIX environments, R.app doesn't make use of command-line arguments. When using Terminal, however, you can pass arguments to customize the R session. For example:
R --vanilla # Start R without loading any saved workspace
R --slave # Run R in batch mode for scripting
Setting the Home Directory
The 'home directory' within Terminal.app is the one inside the R.framework. This is where R looks for system-wide configuration files.
Managing Working Directories
The startup and current working directory in Terminal.app are set to the user's home directory by default. You can change this by specifying a different startup directory when invoking R. For example:
R --args --no-restore --slave -f script.R
Using R.app – The Console-Based GUI
Locating and Launching R.app
R.app is a console-based GUI that provides a user-friendly interface for R on macOS. It's typically found in the Applications folder, and you can launch it by double-clicking the application icon.
Preferences Window
R.app includes a Preferences window accessible from within the GUI. To access it, click on 'R' in the menu bar, then select 'Preferences.' Here, you can customize various settings, including the startup directory.
Setting Startup Directory
In R.app, the startup and current working directory are, by default, the user's home directory. However, you can change the startup directory by modifying the preferences. This is particularly useful when you want to organize your work and access specific project folders easily.