Comments in R Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 29 Likes Like Report In R Programming Language, Comments are general English statements that are typically written in a program to describe what it does or what a piece of code is designed to perform. More precisely, information that should interest the coder and has nothing to do with the logic of the code. They are completely ignored by the compiler and are thus never reflected on the input. Comments are generally used for the following purposes:Code ReadabilityExplanation of the code or Metadata of the projectPrevent execution of codeTo include resourcesTypes of Comments There are generally three types of comments supported by languages :Single-line Comments: Comment that only needs one lineMulti-line Comments: Comment that requires more than one line.Documentation Comments: Comments that are drafted usually for a quick documentation lookupNote: R doesn't support Multi-line and Documentation comments. It only supports single-line comments drafted by a '#' symbol. 1. Single-Line Comments in RSingle-line comments are comments that require only one line. They are usually drafted to explain what a single line of code does or what it is supposed to produce so that it can help someone refer to the source code. Just like Python single-line comments, any statement starting with "#" is a comment in R. Syntax: # comment statement Example 1: R # geeksforgeeks The above code when executed will not produce any output, because R will consider the statement as a comment and hence the compiler will ignore the line. Example 2: R # R program to add two numbers # Assigning values to variables a <- 9 b <- 4 # Printing sum print(a + b) Output:[1] 132. Multi-line Comments in RAs stated earlier that R doesn't support multi-lined comments, but to make the commenting process easier, R allows commenting on multiple single lines at once. There are two ways to add multiple single-line comments in R Studio: First way: Select the multiple lines on which you want to comment using the cursor and then use the key combination "control + shift + C" to comment or uncomment the selected lines. R # This is a multiple-line comment # Each line starts with the '#' symbol # The following code will be executed x <- 10 y <- 20 sum <- x + y print(sum) # This line will print the value of 'sum' Output:[1] 30Second way: The other way is to use the GUI, select the lines on which you want to comment by using the cursor and click on "Code" in the menu, a pop-up window pops out in which we need to select "Comment/Uncomment Lines" which appropriately comments or uncomment the lines which you have selected. This makes the process of commenting a block of code easier and faster than adding # before each line one at a time. Comment V vanshikagoyal43 Follow 29 Improve V vanshikagoyal43 Follow 29 Improve Article Tags : R Language R-basics Explore R Tutorial | Learn R Programming Language 4 min read IntroductionR Programming Language - Introduction 4 min read Interesting Facts about R Programming Language 4 min read R vs Python 5 min read Environments in R Programming 3 min read Introduction to R Studio 4 min read How to Install R and R Studio? 4 min read Creation and Execution of R File in R Studio 5 min read Clear the Console and the Environment in R Studio 2 min read Hello World in R Programming 2 min read Fundamentals of RBasic Syntax in R Programming 3 min read Comments in R 3 min read R-Operators 5 min read R-Keywords 2 min read R-Data Types 5 min read VariablesR Variables - Creating, Naming and Using Variables in R 5 min read Scope of Variable in R 5 min read Dynamic Scoping in R Programming 5 min read Lexical Scoping in R Programming 4 min read Input/OutputTaking Input from User in R Programming 7 min read Printing Output of an R Program 4 min read Print the Argument to the Screen in R Programming - print() Function 2 min read Control FlowControl Statements in R Programming 4 min read Decision Making in R Programming - if, if-else, if-else-if ladder, nested if-else, and switch 3 min read Switch case in R 2 min read For loop in R 5 min read R - while loop 5 min read R - Repeat loop 2 min read goto statement in R Programming 2 min read Break and Next statements in R 3 min read FunctionsFunctions in R Programming 5 min read Function Arguments in R Programming 4 min read Types of Functions in R Programming 6 min read Recursive Functions in R Programming 4 min read Conversion Functions in R Programming 4 min read Data StructuresData Structures in R Programming 4 min read R Strings 6 min read R-Vectors 4 min read R-Lists 6 min read R - Array 7 min read R-Matrices 10 min read R-Factors 4 min read R-Data Frames 6 min read Object Oriented ProgrammingR-Object Oriented Programming 7 min read Classes in R Programming 3 min read R-Objects 3 min read Encapsulation in R Programming 3 min read Polymorphism in R Programming 6 min read R - Inheritance 7 min read Abstraction in R Programming 3 min read Looping over Objects in R Programming 5 min read S3 class in R Programming 8 min read Explicit Coercion in R Programming 3 min read Error HandlingHandling Errors in R Programming 3 min read Condition Handling in R Programming 5 min read Debugging in R Programming 3 min read Like