Simple question about comment code aesthetics (color):
I recently noticed in someone's comment code that part of their comment color changed while using the @
symbol. After experimenting with it, I noticed you also need to have an apostrophe ('
) right after the octothorp (#
) as such:
#' @text
^--- This turned orange!
Since I'm a detailed commenter, I'd love to step things up if I could by adding color to my comments. I know part of the reason is my global IDE (RStudio) options, but I'd never seen anything change a comment's color before, so I was just curious:
@
used when handling large, more-complex objects that need further specification => Ex. LargeObject@data$variable
""
), but quotes do not change color when they're commented out with an octothorp (#
).#comment# print(summary(df))
The special highlighting you're seeing — words being highlighted after #' @
— is specific to roxygen markup (a documentation-generation system for R). I don't know why that category doesn't seem to be listed/themeable (see #2).
The RStudio syntax highlighting colours are customizable (you can edit these themes visually), but based on what's documented at the link, there appears to be only one category for "comments".
This question has to do with the R parser, not the RStudio highlighting system. So the answer is "no"; everything from the first #
on a line to the line break is considered a comment, no exceptions. In principle you could adjust the RStudio highlighting engine to recognize various delimiters within comments and display material following them differently, but you can't create in-line comments (as you could with /* */
in C) without modifying the R parser.