R Comments
Comments are primarily used for code interpretation, making it easier for readers to understand. Comments in programming languages are ignored by the compiler and do not affect code execution.
Typically, programming languages have single-line and multi-line comments, but R only supports single-line comments, denoted by the #
symbol.
In fact, for multi-line comments, we simply need to add the #
symbol to each line.
Single-line Comment
# This is my first programming code
myString <- "Hello, World!"
print ( myString )
Multi-line Comment
# R implementation to add two numbers
# Variable assignment
a <- 9
b <- 4
# Output result
print(a + b)
There is also a workaround for multi-line comments, which involves using the if statement, as shown in the following example:
Multi-line Comment
if(FALSE) {
"
This is an example of a multi-line comment
The comment content is placed within single or double quotes
"
}
myString <- "Hello, World!"
print ( myString)