1. Start working with the editor, not the console


When starting up R, you might be confronted with a feeling of “being lost at sea”. Few icons, few menus, not much of a welcoming screen… just a menu bar and the R console. You’ll soon realize that you can write “stuff” in this R console. You can write arithmetical operations, lines of codes and so on.

Start up with R

“Start working with the editor, not the console” is by no mean an order! It is more like a good friend’s advice! Although you will find out that you can actually type in all sorts of commands and get results to your commands directly in the R console, many R users will tell you that this is not only unpractical, but also not adapted to working with projects which require more than a few lines of commands.

Working in the editor window allows you to save your work in a separate file that you may reopen later on. This allows you thus to keep track of all the commands and modifications that you have done in a project. It allows you to work on separate projects in parallel, without mixing codes and lines. It also gives you the opportunity to modify a command that failed because of a mistake/typo and to retry it with minor corrections.

To open an R editor window, you just have to open a (new) script by choosing New script in the File menu (see the result below). CTRL+N may be used for the same purpose, but only when another script window is both opened and active.

new script

Commands which are typed in the R editor window can be processed by simply placing the cursor at the end of the command or by selecting/highlighting the command and pressing CTRL+R (or Edit>Run line or selection), as shown below. The result is then displayed in the R console window.

In this series of tutorials, you will find codes and examples displayed in the following form (see below). You may copy it (without the line numbers to the left) and paste it in your script window to try the code on your own and see that everything works as it should. To activate the code in R and get the result in the R console, select it and press CTRL+R:

[code language=”r”]
(5+6)*4
[/code]

script to console

script to console2

 

 

 

 

 

 

At any time, you may save the script currently in use by pressing CTRL+S (File>Save). Give it a name and a clever location on your hard drive and go get some rest. Whenever you are ready to resume, press CTRL+O (File>Open script...) and locate your script to reopen it.

  Fant du det du lette etter? Did you find this helpful?
[Average: 5]