Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

R Comments

R Comments

Comments are mainly used to explain a piece of code, making it easier for readers to understand; comments in a programming language are ignored by the compiler and do not affect code execution.

Comments in most programming languages are divided into single-line and multi-line comments, but R only supports single-line comments, with # as the comment symbol.

In fact, for multi-line comments we only need to add a # at the beginning of each line.

Single-line comment

This is my first programming code

myString

<-

"Hello, World!"

print

(

myString

)

Multi-line comment

Add two numbers in R

 

Variable assignment

a

<-

9

b

<-

4

 

Output result

print

(

a

b

)

Actually, there is a workaround for multi-line comments: using the if statement, as in the following example:

Multi-line comment

if

(

FALSE

)

{

   

"
    This is an example of a multi-line comment
    Place the comment content between single or double quotes
    "

}

myString

<-

"Hello, World!"

print

(

myString

)