R Comments


Comments

Comments can be used to describe the R code, making it more readable. It may also be used to prevent usage when testing another code.

Comments start with #. When using R-code, R will ignore anything that starts with #.

This example uses comments before the line of code:

Example
# This is a comment
"Hello World!"

This example uses comments at the end of the code line:

Example
"Hello World!" # This is a comment

Comments do not need to be text to explain the code, they can also be used to prevent R from using the code:

Example
# "Good morning!"
"Good night!"


Multiline Comments

Unlike other programming languages, such as Java, there is no syntax in R for multiple line comments. However, we can simply add # to each line to create more line comments:

Example
# This is a comment
# written in
# more than just one line
"Hello World!"