3

When using spin in package knitr, how does one simply comment things out to make them invisible to spin? roxygen style lines (#') are taken as lines to appear in the report. The usual R comment # is taken as an R comment and appears in a code block. Lines that are just text, with no special character at the beginning, cause an error. Lines beginning withe the LaTeX comment % cause an error. However, plain lines that follow the start of a chunk are taken to be part of the chunk and appear in the code block (#+ or #-). So is there a character/symbol that functions to mark a comment line in the true sense of the word?

EDIT: If it has to be invented, the LaTeX comment character % would be quite handy. Just saying.

Bryan Hanson
  • 6,055
  • 4
  • 41
  • 78
  • I guess I did not answer your question completely -- do you want to comment out code lines or normal text lines? I answered the latter. If you want certain code lines to be omitted, you can use `echo=-numbers` as described by Romain below. – Yihui Xie Jul 16 '13 at 03:49
  • Thanks Yihui. The functionality I think would be nice (for troubleshooting/convenience) is to be able to block any type of line so that the `spin` parser just simply ignores it. A single character at the start of the line which can be easily added/removed, in the spirit of universal comments. If this sounds generally useful I could put it in a feature request. – Bryan Hanson Jul 16 '13 at 11:59
  • Feature request received. Coding now. – Yihui Xie Jul 16 '13 at 19:16
  • Please test the new feature described below. Thanks! (It is open to suggestions) – Yihui Xie Jul 17 '13 at 01:34

2 Answers2

3

Update: I added the feature of comments for spin() in knitr 1.3.2 (see its Github repos for installation instructions). Now you can

#' normal text
#' 

# /* a comment here
runif(10)
# and here */

rnorm(5)
#' text continues

Old answer:

That depends on the output format. For example, for LaTeX, you use %:

#' normal text
#' 
#' % a LaTeX comment here
rnorm(5)
#' text continues

For HTML, it is <!-- -->:

#' normal text
#' 
#' <!-- an HTML comment here -->
rnorm(5)
#' text continues
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Thank you Yihui, you are very generous with your time. This is a very helpful feature, and it works as advertised. Bryan – Bryan Hanson Jul 17 '13 at 13:25
0

A long winded solution would be to "echo and eval out" the offending line via the corresponding echo and eval arguments.

#' Regular text

#+ first_chunk, echo = -2, eval = -2
rnorm(10)
runif(20)

#' Text after the chunk
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Hmmm... naturally, I was hoping for a solution in which I could select lines of text and prepend the neeeded character... Thank you though. – Bryan Hanson Jul 15 '13 at 22:14