【问题标题】:Is it possible to call knitr::spin on two different R scripts and produce a single html file?是否可以在两个不同的 R 脚本上调用 knitr::spin 并生成一个 html 文件?
【发布时间】:2016-10-10 19:41:57
【问题描述】:

我有两个不同的 R 脚本。我喜欢 knitr::spin 的想法。我想知道是否有一种方法可以在这两个脚本上调用 spin,它们都使用 roxygen2 格式化并生成一个报告。

【问题讨论】:

  • 您可以 source() 使用 results='asis' 选项。见github.com/yihui/knitr/issues/621。这会是你想要的吗?
  • source 将仅在您使用 print 函数时打印结果,否则它们将被“隐藏”。 source 也不会呈现 rocygen2 文本。您可以使用spin_child,在 KenM 指出的同一链接中提到,但spin_child 行也出现在报告中,这有点烦人。
  • > source 也不会渲染 rocygen2 文本。完全错过了。谢谢!

标签: r knitr knitr-spin


【解决方案1】:

您可以在spin 函数中使用text 参数。使用readLines 读取文件,然后使用cat 写入输出:

cat (spin (text = c (readLines ("file_one.r"),
                     readLines ("file_two.r"))),
     file = "output.html")

【讨论】:

  • 啊!好的和简单的解决方案。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-04
  • 1970-01-01
  • 1970-01-01
  • 2019-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多