2.3 Editing Code

Often we will be interacting with R by writing code and sending that code to the R Interpreter so that it can be run (locally or remotely). It is always good practice to store this code into a file so that we have a record of what we have done and are able to replicate the work at a later time. Such a file is called an R Script.

We can create a new R Script by clicking on the first icon on the RStudio toolbar and choosing the first item in the resulting menu as in Figure @ref(intro:fig:rstudio_startup_editor). A keyboard shortcut is also available to do this: Ctrl+Shift+N (hold the Ctrl and the Shift keys down and press the N key).

A sophisticated file editor is presented as the top left pane within RStudio. The tab will initially be named Untitled1 until we actually save the script to a file on the disk. When we do so we will be asked to provide a name for the file.

The editor is where we write our R code and compose the programs that instruct the computer to perform particular tasks. The editor provides numerous features that are expected in a modern program editor. These include syntax colouring, automatic indentation to improve layout, automatic command completion, interactive command documentation, and the ability to send specific commands to the R Console to have them run by the R Interpreter.

RStudio: Ready to program in R. {#intro:fig:rstudio_startup_editor} Ready to edit R scripts in RStudio using the Editor pane on the top left created when we choose to add a new R Script from the toolbar menu displayed by clicking the icon highlighted in red.

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0