Roxygen comments involve prefixing lines with #'
.
When writing and testing examples for functions, it's nice to be able to toggle the comments on and off. I could copy and paste the code back and forward to vim and remove or add those comments, but that's not very elegant.
Update: Thinking laterally, I suppose using @example examples/foo.r
is an alternative way of avoiding having to use Roxygen comments for the actual example code (i.e., by sourcing the example from a file, i.e., examples/foo.r
).
With respect to your proposed alternative:
If you press CTRL+[Enter] within a Roxygen2 @examples
block, Rstudio will send the selected code (line or highlighted section) to the R console. To use just declare the @examples
code block on a line preceding your roxygen commented code.
#' @examples
#' ... your original roxygen commented code ...
You can put an @examples
block anywhere in your code. This becomes a drag if you are developing a package and you are using the block for its intended purpose.
If you are looking for a way to toggle code, I would use the approach proposed by @Roman in in the comments to your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With