R Comments
Comments are mainly used to explain a piece of code, making it easier for readers to understand. Comments in programming languages are ignored by the compiler and do not affect the execution of the code.
Generally, comments in programming languages are divided into single-line comments and multi-line comments, but the R language only supports single-line comments. The comment symbol is#。
Actually, if you need multi-line comments, you just need to add#the symbol to each line, and that's it.
Single-line comment
# This is my first programming code
myString <- "Hello, World!"
print ( myString )
myString <- "Hello, World!"
print ( myString )
Multi-line comment
# R language: add two numbers
# Variable assignment
a <- 9
b <- 4
# Output result
print(a + b)
# Variable assignment
a <- 9
b <- 4
# Output result
print(a + b)
Actually, there is another workaround for multi-line comments, which is using an if statement, as in the following example:
Multi-line comment
if(FALSE) {
"
This is an example of a multi-line comment
The comment content is placed between single quotes or double quotes
"
}
myString <- "Hello, World!"
print ( myString)
"
This is an example of a multi-line comment
The comment content is placed between single quotes or double quotes
"
}
myString <- "Hello, World!"
print ( myString)