Tutorials References Menu

R Comments


Comments

Comments can be used to explain R code, and to make it more readable. It can also be used to prevent execution when testing alternative code.

Comments starts with a #. When executing the R-code, R will ignore anything that starts with #.

This example uses a comment before a line of code:

Example

# This is a comment
"Hello World!"
Try it Yourself »

This example uses a comment at the end of a line of code:

Example

"Hello World!" # This is a comment
Try it Yourself »

Comments does not have to be text to explain the code, it can also be used to prevent R from executing the code:

Example

# "Good morning!"
"Good night!"
Try it Yourself »

Multiline Comments

Unlike other programming languages, such as Java, there are no syntax in R for multiline comments. However, we can just insert a # for each line to create multiline comments:

Example

# This is a comment
# written in
# more than just one line
"Hello World!"
Try it Yourself »