Installing R and RStudio

To get started with R, yous demand to acquire your own re-create. This appendix volition show you how to download R likewise as RStudio, a software awarding that makes R easier to use. You'll get from downloading R to opening your first R session.

Both R and RStudio are free and piece of cake to download.

How to Download and Install R

R is maintained by an international team of developers who make the language available through the web page of The Comprehensive R Archive Network. The top of the spider web page provides three links for downloading R. Follow the link that describes your operating system: Windows, Mac, or Linux.

Windows

To install R on Windows, click the "Download R for Windows" link. Then click the "base of operations" link. Adjacent, click the first link at the top of the new folio. This link should say something similar "Download R 3.0.three for Windows," except the three.0.3 will be replaced by the most current version of R. The link downloads an installer plan, which installs the most up-to-date version of R for Windows. Run this program and step through the installation sorcerer that appears. The wizard volition install R into your program files folders and place a shortcut in your Start menu. Note that you'll need to accept all of the appropriate administration privileges to install new software on your motorcar.

Mac

To install R on a Mac, click the "Download R for Mac" link. Next, click on the R-3.0.3 package link (or the package link for the most electric current release of R). An installer will download to guide you through the installation process, which is very easy. The installer lets you lot customize your installation, just the defaults volition be suitable for nigh users. I've never establish a reason to modify them. If your computer requires a countersign before installing new progams, you'll need it hither.

Binaries Versus Source

R tin can be installed from precompiled binaries or congenital from source on whatsoever operating system. For Windows and Mac machines, installing R from binaries is extremely easy. The binary comes preloaded in its own installer. Although you tin build R from source on these platforms, the process is much more complicated and won't provide much do good for nearly users. For Linux systems, the opposite is true. Precompiled binaries tin exist found for some systems, only it is much more common to build R from source files when installing on Linux. The download pages on CRAN'southward website provide information virtually building R from source for the Windows, Mac, and Linux platforms.

Linux

R comes preinstalled on many Linux systems, but you'll want the newest version of R if yours is out of date. The CRAN website provides files to build R from source on Debian, Redhat, SUSE, and Ubuntu systems nether the link "Download R for Linux." Click the link and then follow the directory trail to the version of Linux you wish to install on. The verbal installation process volition vary depending on the Linux system y'all utilize. CRAN guides the process by grouping each set of source files with documentation or README files that explain how to install on your organization.

32-bit Versus 64-bit

R comes in both 32-bit and 64-chip versions. Which should you apply? In almost cases, it won't matter. Both versions utilise 32-bit integers, which means they compute numbers to the same numerical precision. The deviation occurs in the way each version manages memory. 64-bit R uses 64-fleck retention pointers, and 32-flake R uses 32-bit retention pointers. This means 64-chip R has a larger memory space to utilize (and search through).

As a rule of pollex, 32-scrap builds of R are faster than 64-scrap builds, though not always. On the other hand, 64-fleck builds can handle larger files and data sets with fewer retentivity management bug. In either version, the maximum allowable vector size tops out at effectually 2 billion elements. If your operating system doesn't support 64-bit programs, or your RAM is less than iv GB, 32-bit R is for you lot. The Windows and Mac installers volition automatically install both versions if your system supports 64-bit R.

Using R

R isn't a program that you lot can open and start using, like Microsoft Word or Net Explorer. Instead, R is a estimator language, like C, C++, or UNIX. You use R by writing commands in the R language and asking your computer to interpret them. In the old days, people ran R code in a UNIX terminal window—as if they were hackers in a movie from the 1980s. At present virtually everyone uses R with an application called RStudio, and I recommend that you do, too.

R and UNIX

Yous can still run R in a UNIX or Bash window by typing the control:

              R            

which opens an R interpreter. You can then do your work and close the interpreter by running q() when you are finished.

RStudio

RStudio is an awarding like Microsoft Word—except that instead of helping yous write in English, RStudio helps y'all write in R. I use RStudio throughout the volume because it makes using R much easier. Also, the RStudio interface looks the same for Windows, Mac Bone, and Linux. That volition help me match the volume to your personal feel.

Yous can download RStudio for costless. Simply click the "Download RStudio" button and follow the simple instructions that follow. One time you've installed RStudio, y'all can open it similar whatsoever other program on your computer—usually by clicking an icon on your desktop.

The R GUIs

Windows and Mac users unremarkably practise not program from a final window, so the Windows and Mac downloads for R come with a uncomplicated programme that opens a last-similar window for y'all to run R code in. This is what opens when you lot click the R icon on your Windows or Mac reckoner. These programs do a little more than than the basic terminal window, but not much. You may hear people refer to them as the Windows or Mac R GUIs.

When you open RStudio, a window appears with three panes in it, as in Figure A.1. The largest pane is a console window. This is where you'll run your R lawmaking and run across results. The console window is exactly what you'd see if you lot ran R from a UNIX console or the Windows or Mac GUIs. Everything else yous meet is unique to RStudio. Subconscious in the other panes are a text editor, a graphics window, a debugger, a file managing director, and much more. You'll acquire well-nigh these panes as they become useful throughout the course of this book.

The RStudio IDE for R.

Figure A.1: The RStudio IDE for R.

Exercise I still demand to download R?

Even if you use RStudio, you'll yet demand to download R to your computer. RStudio helps you use the version of R that lives on your computer, but it doesn't come with a version of R on its ain.

Opening R

Now that y'all have both R and RStudio on your estimator, you can begin using R by opening the RStudio plan. Open RStudio just as yous would any program, past clicking on its icon or by typing "RStudio" at the Windows Run prompt.