Installing R and RStudio

To go started with R, you need to acquire your own re-create. This appendix will show you how to download R as well as RStudio, a software application that makes R easier to apply. You lot'll get from downloading R to opening your commencement 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 height of the 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. So click the "base" link. Next, click the kickoff link at the height of the new page. This link should say something like "Download R 3.0.3 for Windows," except the 3.0.3 will be replaced by the most current version of R. The link downloads an installer program, which installs the most up-to-date version of R for Windows. Run this program and step through the installation magician that appears. The sorcerer will install R into your program files folders and identify a shortcut in your First bill of fare. Note that you'll demand to accept all of the appropriate administration privileges to install new software on your machine.

Mac

To install R on a Mac, click the "Download R for Mac" link. Next, click on the R-3.0.3 parcel link (or the package link for the most electric current release of R). An installer will download to guide you through the installation procedure, which is very piece of cake. The installer lets you customize your installation, but the defaults will be suitable for most users. I've never constitute a reason to change them. If your calculator requires a password before installing new progams, you'll need it here.

Binaries Versus Source

R can exist installed from precompiled binaries or congenital from source on any operating arrangement. For Windows and Mac machines, installing R from binaries is extremely easy. The binary comes preloaded in its own installer. Although you can build R from source on these platforms, the process is much more complicated and won't provide much benefit for most users. For Linux systems, the opposite is truthful. Precompiled binaries tin can be constitute for some systems, but it is much more common to build R from source files when installing on Linux. The download pages on CRAN's website provide information well-nigh 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 under the link "Download R for Linux." Click the link and so follow the directory trail to the version of Linux you wish to install on. The exact installation procedure will vary depending on the Linux system you use. 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-fleck Versus 64-bit

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

Equally a rule of thumb, 32-bit builds of R are faster than 64-bit builds, though not always. On the other hand, 64-bit builds tin handle larger files and data sets with fewer retentiveness direction problems. In either version, the maximum allowable vector size tops out at effectually ii 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 yous. The Windows and Mac installers will automatically install both versions if your system supports 64-bit R.

Using R

R isn't a plan that you lot can open and start using, like Microsoft Word or Internet Explorer. Instead, R is a computer language, similar C, C++, or UNIX. You use R by writing commands in the R language and request your computer to translate them. In the old days, people ran R code in a UNIX concluding window—every bit if they were hackers in a picture show from the 1980s. Now nigh everyone uses R with an application called RStudio, and I recommend that you lot practice, too.

R and UNIX

You can still run R in a UNIX or BASH window past typing the command:

              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 application like Microsoft Word—except that instead of helping you write in English, RStudio helps you write in R. I use RStudio throughout the book because information technology makes using R much easier. Also, the RStudio interface looks the same for Windows, Mac Os, and Linux. That volition aid me friction match the book to your personal feel.

You can download RStudio for free. Just click the "Download RStudio" button and follow the simple instructions that follow. Once yous've installed RStudio, y'all can open it similar any other program on your estimator—usually by clicking an icon on your desktop.

The R GUIs

Windows and Mac users usually do not program from a terminal window, so the Windows and Mac downloads for R come with a unproblematic program that opens a terminal-like window for you to run R code in. This is what opens when you click the R icon on your Windows or Mac computer. These programs do a little more than the basic terminal window, simply not much. You may hear people refer to them as the Windows or Mac R GUIs.

When y'all 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 code and see results. The console window is exactly what you'd encounter if you ran R from a UNIX console or the Windows or Mac GUIs. Everything else yous see is unique to RStudio. Subconscious in the other panes are a text editor, a graphics window, a debugger, a file director, and much more than. Yous'll learn about 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.

Do I still demand to download R?

Fifty-fifty if you utilize RStudio, you lot'll nonetheless need to download R to your calculator. RStudio helps y'all utilize the version of R that lives on your estimator, but it doesn't come with a version of R on its own.

Opening R

At present that you lot have both R and RStudio on your figurer, you can brainstorm using R past opening the RStudio program. Open RStudio simply as you would any program, by clicking on its icon or by typing "RStudio" at the Windows Run prompt.