R Comments

Sriparno08's avatar
Published Jan 9, 2022Updated May 23, 2025
Contribute to Docs

A comment is a piece of text within an R program that is not executed. It can be used to provide additional information to aid in understanding the code. It can also serve to “comment out” blocks of code that the programmer doesn’t want executed, such as for archival purposes or debugging. Many languages support single line and multi-line comments. Only single-line comments are supported in R.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn how to code and clean and manipulate data for analysis and visualization with the R programming language.
    • Beginner Friendly.
      14 hours

Syntax

Comments in R begin with a # character. Everything after the # on that line will be ignored. The comment can either go at the beginning of the line or immediately after the code that will be executed:

# This is a comment and won't be executed.
print("This is a line of code that will be executed.")
a <- 3 + 5 # comments can also go at the end of a line of code.
# To have a multi-line comment in R,
# multiple '#' characters must be used
# for each subsequent line.

All contributors

Contribute to Docs

Learn R on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn how to code and clean and manipulate data for analysis and visualization with the R programming language.
    • Beginner Friendly.
      14 hours