1

I have two different R scripts. I love the idea of knitr::spin. I wanted to know if there's a way to call spin on these two scripts which are both formatted with roxygen2 and produce a single report.

Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
  • 1
    You can source() with results='asis' option. See https://github.com/yihui/knitr/issues/621. Would this be what you want? – KenM Oct 10 '16 at 19:50
  • 1
    `source` will only print results if you use the `print` function, if not they will be "hidden". Also `source` will not render the `rocygen2` text. You can use `spin_child` which is mentioned in the same link KenM indicated, But the `spin_child` line appears also in the report which is a bit annoying. – dmontaner Oct 10 '16 at 22:05
  • > Also source will not render the rocygen2 text. Totally missed that. Thanks! – KenM Oct 10 '16 at 22:46

1 Answers1

4

You can use the text parameter in the spin function. Use readLines to read the files and then cat to write the output:

cat (spin (text = c (readLines ("file_one.r"),
                     readLines ("file_two.r"))),
     file = "output.html")
dmontaner
  • 2,076
  • 1
  • 14
  • 17