R Hello World Program

In this tutorial you will learn about the R Hello World Program and its application with practical example.

Creating R Hello World Program

As usual we will start learning R programming by creating “Hello world!” program. The “Hello world!” program is a simplest program that will display some text on the screen. The “Hello world!” program is a simple yet complete program for beginners that illustrates the basic syntax of R programming language. The “Hello world!” program gives you a way to test systems and programming environment.

This tutorial will guide you through writing a basic “Hello World!” program in R. In R Programming, you can do this either by programming it directly in command prompt or you can simply write a program in a file and executing it.

R Command Prompt

Let’s open command prompt and run the following command to start the R Command prompt.

Once you hit the enter, R interpreter will be launched with a prompt symbol as following –

Here, you can start writing your program. In R Command Prompt, you can print the “Hello World!” in following ways –

Example 1:-

Example 2:-

R Script File

Step 1:- Create a file called “hello_world.R” using a text editor program of your choice. The .R file extension is used to specify Rscript file.

Step 2:- Let’s open the “hello_world.R” file that we created, and put the following line of code in it and save it.

The print() is a function that tells the R interpreter to display or output the content inside the parentheses.

Step 3:- Now, open terminal or command prompt and switch to the folder where our “hello_world.R” file is saved. Run the program by typing the following command –

Once the program is executed it will print “Hello World!” as below –

Output:-

Note :- Before executing R Script in the command prompt, PATH has to be added to environment variables in advanced system properties.

 

In this tutorial we have learn about the R Hello World Program and its application with practical example. I hope you will like this tutorial.