Javatpoint Logo
Javatpoint Logo

Syntax of R Programming

R Programming is a very popular programming language which is broadly used in data analysis. The way in which we define its code is quite simple. The "Hello World!" is the basic program for all the languages, and now we will understand the syntax of R programming with "Hello world" program. We can write our code either in command prompt, or we can use an R script file.

R Command Prompt

It is required that we have already installed the R environment set up in our system to work on the R command prompt. After the installation of R environment setup, we can easily start R command prompt by typing R in our Windows command prompt. When we press enter after typing R, it will launch interpreter, and we will get a prompt on which we can code our program.

Syntax of R Programming

"Hello, World!" Program

The code of "Hello World!" in R programming can be written as:

Syntax of R Programming

In the above code, the first statement defines a string variable string, where we assign a string "Hello World!". The next statement print() is used to print the value which is stored in the variable string.

R Script File

The R script file is another way on which we can write our programs, and then we execute those scripts at our command prompt with the help of R interpreter known as Rscript. We make a text file and write the following code. We will save this file with .R extension as:

Demo.R

To execute this file in Windows and other operating systems, the process will remain the same as mentioned below.

Syntax of R Programming

When we press enter it will give us the following output:

Syntax of R Programming

Comments

In R programming, comments are the programmer readable explanation in the source code of an R program. The purpose of adding these comments is to make the source code easier to understand. These comments are generally ignored by compilers and interpreters.

In R programming there is only single-line comment. R doesn't support multi-line comment. But if we want to perform multi-line comments, then we can add our code in a false block.

Single-line comment

The trick for multi-line comment


Syntax of R Programming
Next TopicR Data Types





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA