R Tutorials
R Data Structures
R Graphics
R Statistics
R Examples
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:
# This is a comment
"Hello World!"
This example uses comments at the end of the code line:
"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:
# "Good morning!"
"Good night!"
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:
# This is a comment
# written in
# more than just one line
"Hello World!"