RStudio IDE fails to comment/uncomment certain selected lines in a R Markdown file

RStudio version 1.4.1106, R version 4.0.4 (2021-02-15).

The following is a two-line R fragment.

summary(cars)
plot(pressure)

Select the two lines of code and try to comment them out using either the menus (Code > Comment/Uncomment Lines) or the shortcut key sequence (Ctrl+Shift+C).

I find that the lines are not commented out by the IDE.

Now do the same with the above fragment and select only the first line of code and attempt to comment them out using either the menus or the shortcut key sequence (Ctrl+Shift+C). I find that in this case the line is commented out by the IDE.

In general, selecting lines of code in an R fragment and commenting them (Ctrl+Shift+C) works only if the last selected line is not the last line of the code fragment.

However, if you place the cursor anywhere on the last line (i.e. "plot(pressure)") then Ctrl+Shift+C correctly comments out that last line.

Can anyone confirm the same behaviour?

There was a similar buglet like this reported in late 2017 in Weird behavior when trying to comment a selected line in a R Markdown doc - RStudio IDE - RStudio Community.

Stephen

Sorry, I meant to say that you put the two-line fragment into an RMarkdown document...

Silly me.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.