


Keyboard Shortcutsīeyond the keyboard shortcuts described above, there are a wide variety of other shortcuts available. Setting Source on Save ensures that the copy of a function within the global environment is always in sync with its source, and also provides a good way to arrange for frequent syntax checking as you develop a function.

Enabling this option will cause the file to automatically be sourced into the global environment every time it is saved. When editing re-usable functions (as opposed to freestanding lines of R) you may wish to set the Source on Save option for the document (available on the toolbar next to the Save icon). The difference between running lines from a selection and invoking Source is that when running a selection all lines are inserted directly into the console whereas for Source the file is saved to a temporary location and then sourced into the console from there (thereby creating less clutter in the console). To run the entire document press the Ctrl+Shift+Enter key (or use the Source toolbar button).Note that changes to the selection including additional, removal, and modification of lines will be reflected in this subsequent run of the selection. After executing a selection of code, use the Re-Run Previous Region command (or its associated toolbar button) to run the same selection again.Select the lines and press the Ctrl+Enter key (or use the Run toolbar button) or.There are three ways to execute multiple lines from within the editor: This enables you to single-step through a sequence of lines.
#Rstudio source on save code
To execute the line of source code where the cursor currently resides you press the Ctrl+Enter key (or use the Run toolbar button):Īfter executing the line of code, RStudio automatically advances the cursor to the next line. RStudio supports the direct execution of code from within the source editor (the executed commands are inserted into the console where their output also appears). You can comment and uncomment entire selections of code using the Code -> Comment/Uncomment Lines menu item (you can also do this using the Command+Shift + C keyboard shortcut): Any "free" variables within the selection (objects that are referenced but not created within the selection) are converted into function arguments: RStudio can analyze a selection of code from within the source editor and automatically convert it into a re-usable function. RStudio supports finding and replacing text within source documents:įind and replace can be opened using the Ctrl+F shortcut key, or from the Edit -> Find. menu item.
#Rstudio source on save full
For example, if you have an object named pollResults in your workspace you can type poll and then Tab and RStudio will automatically complete the full name of the object.Ĭode completion also works in the console, and more details on using it can be found in the console Code Completion documentation. RStudio supports the automatic completion of code using the Tab key. If you have a large number of open documents you can also navigate between them using the > icon on the tab bar or the View -> Switch to Tab.) menu item: If you open several files within RStudio they are all available as tabs to facilitate quick switching between open documents. menu or the Recent Files menu to select from recently opened files. To open an existing file you use either the File -> Open File. To create a new file you use the File -> New File menu: RStudio supports syntax highlighting and other specialized code-editing features for: These features are described in the Executing Code section below. Working in the source editor makes it much easier to reproduce sequences of commands and to package commands for re-use as a function. For many R developers this represents their preferred way of working with R. The RStudio IDE also enables you to flexibly execute R code directly from the source editor. The RStudio IDE's source editor includes a variety of productivity enhancing features including syntax highlighting, code completion, multiple-file editing, and find/replace.
