Installing R and RStudio

To get started with R, yous need to learn your ain copy. This appendix will show yous how to download R too as RStudio, a software awarding that makes R easier to use. You'll go from downloading R to opening your first R session.

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

How to Download and Install R

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

Windows

To install R on Windows, click the "Download R for Windows" link. Then click the "base" link. Adjacent, click the beginning link at the height of the new page. This link should say something like "Download R iii.0.3 for Windows," except the 3.0.3 volition exist replaced past 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 wizard volition install R into your program files folders and place a shortcut in your Start menu. Notation that yous'll need to have 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-three.0.3 packet link (or the packet link for the about electric current release of R). An installer volition download to guide you through the installation process, which is very easy. The installer lets you lot customize your installation, but the defaults will be suitable for most users. I've never found a reason to alter them. If your calculator requires a password before installing new progams, yous'll demand information technology hither.

Binaries Versus Source

R tin exist installed from precompiled binaries or built from source on whatever 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 procedure is much more complicated and won't provide much benefit for nearly users. For Linux systems, the contrary is true. Precompiled binaries can be found 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 about edifice 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 engagement. 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 then 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 apply. CRAN guides the process by grouping each set of source files with documentation or README files that explain how to install on your organisation.

32-bit Versus 64-scrap

R comes in both 32-fleck and 64-fleck versions. Which should yous utilize? In most cases, information technology won't matter. Both versions use 32-bit integers, which means they compute numbers to the same numerical precision. The difference occurs in the style each version manages memory. 64-fleck R uses 64-bit memory pointers, and 32-bit R uses 32-scrap retentivity pointers. This means 64-bit R has a larger memory infinite to use (and search through).

Every bit a rule of pollex, 32-bit builds of R are faster than 64-bit builds, though not e'er. On the other hand, 64-fleck builds can handle larger files and data sets with fewer memory management problems. 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 four 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 yous can open up and offset using, similar Microsoft Word or Internet Explorer. Instead, R is a computer linguistic communication, like C, C++, or UNIX. You apply 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. Now well-nigh everyone uses R with an awarding chosen RStudio, and I recommend that yous exercise, too.

R and UNIX

You tin can still run R in a UNIX or Bash window by typing the command:

              R            

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

RStudio

RStudio is an awarding like Microsoft Word—except that instead of helping you lot write in English language, 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 Bone, and Linux. That will help me match the volume to your personal experience.

Y'all can download RStudio for free. Only click the "Download RStudio" button and follow the simple instructions that follow. In one case you've installed RStudio, you lot can open it like whatsoever other programme on your estimator—usually by clicking an icon on your desktop.

The R GUIs

Windows and Mac users usually do not program from a concluding window, and then the Windows and Mac downloads for R come with a simple program that opens a final-like window for y'all to run R lawmaking in. This is what opens when you click the R icon on your Windows or Mac computer. These programs do a picayune more the basic terminal window, simply not much. You may hear people refer to them as the Windows or Mac R GUIs.

When you open RStudio, a window appears with 3 panes in information technology, as in Figure A.i. The largest pane is a console window. This is where yous'll run your R code and see results. The console window is exactly what you'd see if you ran R from a UNIX console or the Windows or Mac GUIs. Everything else you see 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 larn well-nigh these panes as they become useful throughout the form of this book.

The RStudio IDE for R.

Figure A.i: The RStudio IDE for R.

Exercise I still demand to download R?

Fifty-fifty if you use RStudio, you'll withal need to download R to your computer. RStudio helps you lot use the version of R that lives on your figurer, but it doesn't come with a version of R on its own.

Opening R

Now that you take both R and RStudio on your reckoner, y'all can begin using R by opening the RStudio programme. Open RStudio but equally you would any program, by clicking on its icon or past typing "RStudio" at the Windows Run prompt.