Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 17 / 68

Writing comments

This lesson covers writing comments in R, with the aim of making the intent of your code clear to others and to yourself.

A comment is a note for humans that has no effect on execution. In R, # makes the rest of the line a comment.

The sample code shows both a whole-line comment, as in # This is a single-line comment, and an explanation added at the end of a line, as in price <- 100 # product price.

A common early stumble is writing so many comments that the code becomes harder to read. Recording why something is needed is valuable; restating what the code plainly says is not.

In professional work, note that R has no dedicated multi-line comment syntax — for several lines you put # at the start of each.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run R directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)