Comments have multiple uses in R, and they serve different purposes. I suggest that Rstudio should be able to easily recognize those different purposes (which it already can do; see below) and also use differently-colored font to emphasize these differences.
Here are three different ways I use comments (or, the pound symbol #
):
- To comment out bad code
# x <- deprecatedFunction()
- To leave purposeful notes for good documentation
## This converts the matrix into a data.frame
- To document functions in my package, a la roxygen2 (special case)
#' @param data A data.frame
In particular, 1. and 2. have very different uses: I want to remove all the 1.'s and keep all the 2.'s. And when I'm visually scanning a program I'm writing, it would be great if it was easy to tell what comments are the helpful type 2.'s and which comments are the type 1.'s.
Practically, Rstudio could perhaps implement this by associating different colors when the comments are of each of these three types:
-
#
for the first type, the least important -
#"
with a double-quotation symbol to denote a purposeful, important comment -
#'
with a single-quotation symbol to denote a roxygen2-type function documentation
Then the RStudio IDE might be able to tell the difference between these three symbols and print to the screen with these three colors:
- grey
- blue
- green
This would require that the color schemes have extra values for the new types of comments; but I would imagine this is not the tricky part. Again, this would help to improve readability in RStudio. Of course, if there are other IDE's that do this better in a different manner than what I'm proposing, I'm all ears!