R is a computer language. It’s a tool for doing the computation and number-crunching that set the stage for statistical analysis and decision-making. RStudio is an open source integrated development environment (IDE) for creating and running R code. It’s available in versions for Windows, Mac, and Linux. Although you don’t need an IDE in order to work with R, RStudio makes life a lot easier.
Download R from the Comprehensive R Archive Network (CRAN). In your browser, type this address if you work in Windows:
Click the link to download R. This puts the win.exe file in your Windows computer, or the.pkg file in your Mac. In either case, follow the usual installation procedures. When installation is complete, Windows users see an R icon on their desktop, Mac users see it in their Application folder. Both URLs provides helpful links to FAQs. Aug 10, 2018.
Aug 25, 2020. Jul 24, 2016. Dec 31, 2015. 134 time-saving Hotkeys for RStudio. Extensive, exportable, wiki-style reference lists for Keyboard Shortcuts/Hotkeys. Sep 18, 2017.
cran.r-project.org/bin/windows/base/
Type this one if you work on the Mac:
cran.r-project.org/bin/macosx/
Click the link to download R. This puts the win.exe file in your Windows computer, or the .pkg file in your Mac. In either case, follow the usual installation procedures. When installation is complete, Windows users see an R icon on their desktop, Mac users see it in their Application folder.
Both URLs provides helpful links to FAQs. The Windows-related URL also links to “Installation and other instructions.”
Now for RStudio.
Click the link for the installer for your computer, and again follow the usual installation procedures.
After the RStudio installation is finished, click the RStudio icon to open the window shown.
If you already have an older version of RStudio and you go through this installation procedure, the install updates to the latest version (and you don’t have to uninstall the older version).
The large Console pane on the left runs R code. One way to run R code is to type it directly into the Console pane.
The other two panes provide helpful information as you work with R. The Environment and History pane is in the upper right. The Environment tab keeps track of the things you create (which R calls objects) as you work with R. The History tab tracks R code that you enter.
Get used to the word object. Everything in R is an object.
The Files, Plots, Packages, and Help tabs are in the pane in the lower right. The Files tab shows files you create. The Plots tab holds graphs you create from your data. The Packages tab shows add-ons (called packages) you downloaded as part of the R installation. Bear in mind that “downloaded” doesn’t mean “ready to use.” To use a package’s capabilities, one more step is necessary, and you’ll want to use packages.
This figure shows the Packages tab. The packages are in either the user library (which you can see in the figure) or the system library (which you have to scroll down to).
The Help tab, shown here, provides links to a wealth of information about R and RStudio.
To tap into the full power of RStudio as an IDE, click the larger of the two icons in the upper right corner of the Console pane. That changes the appearance of RStudio so that it looks like this:
The top of the Console pane relocates to the lower left. The new pane in the upper left is the Scripts pane. You type and edit code in the Scripts pane and press Ctrl+R (Command+Enter on the Mac), and then the code executes in the Console pane.
Ctrl+Enter works just like Ctrl+R. You can also select Code → Run Selected Line(s)
.
1. Console | |
---|---|
Ctrl+2 | Move cursor to console |
Ctrl+L | Clean console |
Command+Left | Move cursor to beginning of line |
Command+Right | Move cursor to end of line |
Up/Down | Navigate command history |
Command+Up | Popup command history |
Esc | Interrupt currently executing command |
Ctrl+Shift+H | Change working directory |
▲ up
2. Source | |
---|---|
Ctrl+. | Goto file/function |
Ctrl+1 | Move cursor to source editor |
Command+Shift+N | New document (except on chrome/windows) |
Command+Option+Shift+N | New document (Chrome only) |
Command+O | Open document |
Command+S | Save active document |
Command+W | Close active document (except on Chrome) |
Command+Option+W | Close active document (Chrome only) |
Command+Shift+W | Close all open documents |
Command+Shift+K | Preview HTML (markdown and HTML) |
Command+Shift+K | Compile notebook/compile PDF (TeX and Sweave) |
Command+Option+I | Insert chunk (Sweave and Knitr) |
Command+Shift+R | Insert code section |
Command+Enter | Run current line/selection |
Option+Enter | Run current line/selection (retain cursor position) |
Command+Shift+P | Re-run previous region |
Command+Option+R | Run current document |
Command+Option+B | Run from document beginning to current line |
Command+Option+E | Run from current line to document end |
Command+Option+F | Run from current line to document end |
Command+Option+T | Run the current code section |
Command+Option+P | Run previous sweave/Rmd code |
Command+Option+C | Run the current Sweave/Rmd chunk |
Command+Option+N | Run the next Sweave/Rmd chunk |
Command+Shift+O | Source a file |
Command+Shift+S | Source the current document |
Command+Shift+Enter | Source the current document (with echo) |
Command+Option+L | Fold selected |
Command+Shift+Option+L | Unfold selected |
Commad+Option+O | Fold all |
Commad+Shift+Option+O | Unfold all |
Commad+Shift+Option+G | Go to line |
Commad+Shift+Option+J | Jump to |
Ctrl+Shift+. | Switch to tab |
Ctrl+F11 | Previous tab |
Ctrl+F12 | Next tab |
Ctrl+Shift+F11 | First tab |
Ctrl+Shift+F12 | Last tab |
Command+F9 | Navigate back |
Command+F10 | Navigate forward |
Command+Option+X | Extract function from selection |
Command+Option+V | Extract variable from selection |
Command+I | Reindent lines |
Command+Shift+C | Comment/uncomment current line/selection |
Command+Shift+/ | Reflow comment |
Command+Shift+A | Reformat selection |
Command+Shift+Shift+P | Show diagnostics |
Option+Up/Down | Move lines Up/Down |
Command+Option+Up/Down | Copy lines Up/Down |
Ctrl+P | Jump to matching Brace/Paren |
Ctrl+Shift+E | Expand to matching Brace/Paren |
Command+Shift+Option+E | Select to matching Brace/Paren |
Ctrl+Option+Up | Add cursor above current cursor |
Command+Option+Down | Add cursor beow current cursor |
Ctrl+Option+Shift+Up | Move active cursor up |
Ctrl+Option+Shift+Down | Move Active Cursor Down |
Command+F | Find and replace |
Commad+G | Find next |
Commad+Shift+F3 | Find previous |
Command+E | Use selection for find |
Command+Shift+J | Replace and find |
Command+Shift+F | Find in files |
F7 | Check spelling |
▲ up
3. Completions (Console and Source) | |
---|---|
Tab/Command+Space | Attempt completion |
Up/Down | Navigate candidates |
Enter/Tab/Right | Accept selected candidate |
Esc | Dismiss completion popup |
▲ up
4. Views | |
---|---|
Command+1 | Move focus to Source Editor |
Command+2 | Move focus to Console |
Command+3 | Move focus to Help |
Command+4 | Show History |
Command+5 | Show files |
Command+6 | Show plots |
Command+7 | Show packages |
Command+8 | Show environment |
Command+9 | Show git/svn |
Command+0 | Show build |
Command+F8 | Sync editor & pdf preview |
Option+Shift+K | Reference |
▲ up
5. Build | |
---|---|
Command+Shift+B | Build and reload |
Command+Shift+L | Load all (devtools) |
Command+Shift+T | Test package (desktop) |
Command+Option+F7 | Test package (web) |
Command+Shift+E | Check package |
Command+Shift+D | Document package |
▲ up
6. Debug | |
---|---|
Shift+F9 | Toggle breakpoint |
F10 | Execute next line |
Shift+F4 | Step into function |
Shift+F6 | Finish function/loop |
Shift+F5 | Continue |
Shift+F8 | Stop debugging |
▲ up
7. Plots | |
---|---|
Command+Option+F11 | Previous plot |
Command+Option+F12 | Next plot |
▲ up
8. Git / SVN | |
---|---|
Ctrl+Option+D | Diff active source document |
Ctrl+Option+M | Commit changes |
Ctrl+Up/Down | Scroll diff view |
Spacebar | Stage/unstage(Git) |
Enter | Stage/unstage and move to next (Git) |
▲ up
9. Session | |
---|---|
Command+Q | Quit Session (desktop only) |
Command+Shift+F10 | Restart R Session |
▲ up
10. Editing (Console and Source) | |
---|---|
Command+Z | Undo |
Command+Shift+Z | Redo |
Command+X | Cut |
Command+C | Copy |
Command+V | Paste |
Command+A | Select all |
Command+Left/Right | Jump to word |
Command+Home/End/Command+Up/Down | Jump to start/end |
Command+D | Delete line |
Shift+Arrow | Select |
Option+Shift+Left/Right | Select word |
Command+Shift+Left | Select to line start |
Command+Shift+RIght | Select to line end |
Shift+Page Up/Shift+Page down | Select page up/down |
Command+Shift+Home/End | Select page start/end |
Option+Backspace | Delete word left |
Tab | Indent |
Shift+Tab | Outdent |
Ctrl+U | Yank line up to cursor |
Ctrl+K | Yank line after cursor |
Ctrl+Y | Insert currently yanked text |
Option+- | Insert assignment operator |
Command+Shift+M | Insert pipe operator |
F1 | Show help for function at cursor |
F2 | Show source code for function at cursor |
Command+Option+U | Find usages for symbol at cursor (C++) |
Check R Version In Rstudio
▲ up