R Console/Interface

R Console/Interface

R console is one of the basic and simple editor for R programming. There are more advanced IDEs (Integrated Development Environment) which we will see in upcoming tutorials. Let’s get started through R console and some basic programming

Open the console application which can be found in desktop shortcut or at C:\Program Files\R\R-3.3.1\bin\x64 (64-bit) and C:\Program Files\R\R-3.3.1\bin\i386\Rgui.exe (32-bit)


Once opened your R console looks like below.


In the screenshot we see basic details about R like it’s version, platform on which it is running, license details, language support, contribution towards R, how to view a demo, get help and quit R console. Now let’s start with the programming. R programming is simple and easy to write code and execute. Just like any other programming language let’s start with the famous Hello World

Hello World

In R console you see a prompt > where you can start typing your program as follows −Type

and press Enter Key


From the above example we see that string can be added with single quotes (”) or double quotes (“”). R is however case sensitive. Hence

will result in below error.

Error: could not find function “PRINT”

You can save the program by clicking on Save Workspace from Toolbar or from File Menu.
HURRAY!! Congratulations. Now you have written your first R program and saved it.

In the above example we directly wrote the program in R console. In our traditional programming approach we usually write code behind files or new script files and save the program. Let’s follow the same approach here.

How to create a new script file in R?

Go to File option and select new scriptrconsole
A new editor window opens with name “Untitled R editor” as below:screenshot_1

Let’s type the same program as executed in console earlier. The first line in the script file is a comment which is for understanding and this line doesn’t get executed. Comments in R are prefixed with # character.

Save the file from File Menu. File extension for R script files is “.R”.
After saving close the script file. Now let’s call the script from the console and see the result.

Source command accepts two parameter. The file path and the ECHO parameter. For the file path we can mention the full absolute path of the file with in quotes or just mention the file name only if the file is saved in root working directory of R. echo is an optional parameter. Setting echo as TRUE displays the actual program and also the execution result. Without echo parameter or with echo=FALSE we will just see the execution result.
With Echo:screenshot_1
Without Echo:


Now you might be well versed with R console. In the next topic let’s go through about other editors available for R.

Leave a Reply

Your email address will not be published. Required fields are marked *