Dear Posit Community,
As programming languages, R and Rmarkdown enable us to
- express instructions for computers to execute
- express these instructions in ways that we humans can understand.
When it comes to writing understandable code, the ball's in our court as programmers, but programming language syntax and semantics determine what' s possible, e.g., compare
- APL: {(+⌿⍵)÷≢⍵}
- R:
mean(w, na.rm=TRUE)
Integrated Development Environments (IDEs) like RStudio can also play a powerful role, and I'm particularly interested here in the way they can allow us to write one thing (e.g., $e^{i \pi}+1=0$
, [Posit Forum](https://forum.posit.co/)
) which displays in another way.
This makes me think about interstital comments, i.e., comments in the interstices—the intervening gaps between other things. Languages like C have them, e.g.,
int i /* index over rows */ = N - 1 /* last row */;
...though I haven't seen much code that tries to take advantage of this style.
R, however, has only # comments to end of line
...which limits the kinds of comments we can make.
Now, as someone who has experienced the frustration of trying to change code that was actually within a multiline comment (a long time ago, in a vi
editor far, far away), I suggest the following with some hesitation, but also at a time where IDEs are doing more and more to enable us to communicate better in code.
What do you think about interstital comments «like this» to make our R and Rmarkdown code more understandable?
Imagine using these comments to insert additional text to improve readability:
saveRDS(New_ClassList, «to the local» ClassList_file)
Or providing to provide alternate display text for code, so that the following
saveRDS(New_ClassList, «to local file»⸨ClassList_file⸩)
could be displayed as
saveRDS(New_ClassList, «to local file»)
while being interpreted by R as
saveRDS(New_ClassList, ClassList_file)
I'm curious to know what you think about this kind of literate programming idea, its potential pros and cons, and whether such a thing could ever happen in the R universe.
Cheers,
David