Home »
R Language
Comments in R programming language
Comments in R language: In this tutorial, we are going to learn about the various comments in R programming language with examples.
Submitted by Bhavya Sri Khandrika, on March 18, 2020
Comments in R language
We all are acquainted with the principles or rules that are used while writing the program more clearly in the C language. In the basic C language, the programmers include different types of comment lines to make their program more lucid and understandable. But what is the use of these comment lines?
Comment lines include the line of code or any sort of information that mainly specifies the other programmers (apart from the one who designed the code) about the functionality of that particular piece of code where the comment lines are included. The use of these comment lines is that it makes the program more precise.
In the R language, the comment lines act as the helping text. However, these comment lines are generally ignored by the interpreter when the actual program is being executed.
It is very important for a programmer to know the fact that in the R language the multi-line comments are not supported.
The basic syntax of using a single comment is as follows:
# My first program in R Programming
As stated earlier the R language has it's a limitation in the usage of multiline comments. But still, there is a trick that is widely employed by the programmers in attaining the multiline comments in the R program. To solve the limitation of the multi-line comments the following code assists the programmers in including the multi-line comments in their program.
if(FALSE) {
"This is a multiline comment
The programmer should place it inside a single or double quote"
}
myString <- "Hello, World!"
print (myString)
Output
"Hello, World!"
When the above code is executed then the comments lines are ignored and thus they normally do not interfere with the actual program. The basic rule for including a comment line in the R language is the one must write the comments in either with the Single or double quotation marks.
In the above text we have learned the procedure how the comments lines are included in the programs. But on the other hand, it is quite significant for a programmer to learn what are the main advantages of using a particular attribute in the program he or she works upon. Therefore in order to educate the programmers about the main purpose of using these comments lines here is a short description over the advantages of using comment lines.
To Increase Readability
The main purpose of including these comment lines in the program is to make the program more easily comprehensible for the person who looks over it. Also, whenever in the later times if the programmer who has worked over the creation of a particular code wants to recheck his or her code then these comment lines helps them while going through the main agenda of the program written.
To Debug The Code Written
Also, it helps in debugging the code written. As we all know that the comment lines are not executed during the execution of the program therefore using these comment lines helps us in identifying the error in the particular block of code.