Beginner's guide to R: Introduction

Get started with this popular programming language.

Your first step

To begin using R, head to r-project.org to download and install R for your desktop or laptop. It runs on Windows, OS X and "a wide variety of Unix platforms," but not yet on Android or iOS.

Installing R is actually all you need to get started. However, I'd suggest also installing the free R integrated development environment (IDE) RStudio. It's got useful features you'd expect from a coding platform, such as syntax highlighting and tab for suggested code auto-completion. I also like its four-pane workspace, which better manages multiple R windows for typing commands, storing scripts, viewing command histories, viewing visualizations and more.

RStudio window
Although you don't need the free RStudio IDE to get started, it makes working with R much easier.

The top left window is where you'll probably do most of your work. That's the R code editor allowing you to create a file with multiple lines of R code -- or open an existing file -- and then run the entire file or portions of it.

Bottom left is the interactive console where you can type in R statements one line at a time. Any lines of code that are run from the editor window also appear in the console.

The top right window shows your workspace, which includes a list of objects currently in memory. There's also a history tab with a list of your prior commands; what's handy there is that you can select one, some or all of those lines of code and one-click to send them either to the console or to whatever file is active in your code editor.

The window at bottom right shows a plot if you've created a data visualization with your R code. There's a history of previous plots and an option to export a plot to an image file or PDF. This window also shows external packages (R extensions) that are available on your system, files in your working directory and help files when called from the console.

Learning the shortcuts

Wickham, the RStudio chief scientist, says these are the three most important keyboard shortcuts in RStudio:

  • Tab is a generic auto-complete function. If you start typing in the console or editor and hit the tab key, RStudio will suggest functions or file names; simply select the one you want and hit either tab or enter to accept it.
  • Control + the up arrow (command + up arrow on a Mac) is a similar auto-complete tool. Start typing and hit that key combination, and it shows you a list of every command you've typed starting with those keys. Select the one you want and hit return. This works only in the interactive console, not in the code editor window.
  • Control + enter (command + enter on a Mac) takes the current line of code in the editor, sends it to the console and executes it. If you select multiple lines of code in the editor and then hit ctrl/cmd + enter, all of them will run.

For more about RStudio features, including a full list of keyboard shortcuts, head to the online documentation.

Next: Beginning R commands

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

More about ExcelFacebookGoogleOrbitzTab

Show Comments
[]