My understanding is that knitr:spin
allows me to work on my plain, vanilla, regular ol' good R script, while keeping the ability to generate a full document that understands markdown syntax. (see https://yihui.name/knitr/demo/stitch/)
Indeed, the rmarkdown
feature in Rstudio
, while super neat, is actually really a hassle because
- I need to duplicate my code and break it in chunks which is super boring + inefficient as it is hard to keep track of code changes.
- On top of that
rmarkdown
cannot read my current workspace. This is somehow surprising but it is what it is.
All in all this is very constraining... See here for a related discussion Is there a way to knitr markdown straight out of your workspace using RStudio?.
As discussed here (http://deanattali.com/2015/03/24/knitrs-best-hidden-gem-spin/), spin
seems to be the solution.
Indeed, knitr:spin
syntax looks like the following:
#' This is a special R script which can be used to generate a report. You can
#' write normal text in roxygen comments.
#'
#' First we set up some options (you do not have to do this):
#+ setup, include=FALSE
library(knitr)
in a regular workspace!
BUT note how each line of text is preceded by #'
.
My problem here is that it is also very inefficient to add #'
after each single line of text. Is there a way to do so automatically?
Say I select a whole chunk of text and rstudio adds this #'
every row? Maybe in the same spirit as commenting a whole chunk of code lines?
Am I missing something?
Thanks!