How to Comment Out an Entire Code Block in R (Example Code)

This article illustrates how to comment out a code block in the R programming language.

Example: Put Hashtag in Front of Code Block

Let’s assume that we want to comment out this code block:

some_code <- c(9, 1, 7, 5)       # Just some useless code in R
some_code_2 <- some_code + 1
some_code_3 <- some_code + 2

Then, we have to mark the whole code block and press the keyboard shortcut Control + Shift + c.

This results in the following modification of our code:

# some_code <- c(9, 1, 7, 5)     # Just some useless code in R
# some_code_2 <- some_code + 1
# some_code_3 <- some_code + 2

As you can see, all lines of code have a hashtag in front.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top