← Back to R Course | Chapter 1: Getting Started | Lesson 4 of 6

Comments

In this page:

  1. Comments

Comments

A # starts a comment in R, and everything after it on that line is ignored by the interpreter. R has no multi-line comment syntax, so every comment line needs its own #. Comments should clarify why code does something non-obvious rather than restate what's already clear from the code.

Note: RStudio and most editors let you comment/uncomment a whole selected block at once, adding # to every line.

Example: Comments

markup
# This script demonstrates comments
x <- 10  # inline comment after code
# print(x) -- this line is commented out and won't run
print(x)
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.