【问题标题】:Using DiagrammeR in Word document (generated using rMarkdown)在 Word 文档中使用 DiagrammeR(使用 rMarkdown 生成)
【发布时间】:2015-07-30 04:38:02
【问题描述】:

我一直在查看 diagrammeR 包 (http://rich-iannone.github.io/DiagrammeR/) 以在 rMarkdown 中生成图表。这在以 HTML 格式呈现文档时效果很好;现在我的问题是是否有可能将文档输出为 MS Word 文档?

例如,考虑一下:

---
title: "Test"
author: "Test"
date: "Monday, May 18, 2015"
output: html_document
---

```{r, echo=FALSE, warning=FALSE}
if (!require("DiagrammeR")) library("DiagrammeR")
```

Check out this diagram:

```{r, echo=FALSE, results='asis'}
DiagrammeR::grViz("
      digraph rmarkdown {
      node [shape = box ]
      'A' -> 'B'
      }
      ")
```

使用 HTML 作为输出格式就像一个魅力。但是,当我切换到 MS Word 时,我得到的只是:

Error: Functions that produce HTML output found in document targeting docx output.
Please change the output type of this document to HTML.

任何想法都将不胜感激。

非常感谢,菲利普

【问题讨论】:

  • 我建议直接询问 Richard - 他是 Twitter 上的 riannone。他很有帮助。
  • 请发布你学到的东西,因为这个包可能对组织结构图很有用,还有很多其他的可能性。谢谢。

标签: r r-markdown diagrammer


【解决方案1】:

trelliscope 有用:https://github.com/tesseradata/trelliscope

安装http://phantomjs.org/download.html后, 您可以通过以下方式生成word doc文件:

---
title: "Test"
author: "Test"
date: "Monday, May 18, 2015"
output: word_document
---

```{r include=FALSE}
if (!require("DiagrammeR")) library("DiagrammeR")
library(trelliscope)
```


Check out this diagram:

```{r, include=FALSE}
p = DiagrammeR::grViz("
      digraph rmarkdown {
      node [shape = box ]
      'A' -> 'B'
      }
      ")
widgetThumbnail(p, paste0(getwd(), "/hoge.png"))
```

![](hoge.png)

这是屏幕截图。它看起来很完美:)

【讨论】:

  • 最后我发现thumb.R是tesseradata/trelliscope的一部分:github.com/tesseradata/trelliscope所以我们应该在library(trelliscope)之后做install_github("tesseradata/trelliscope")
  • 您的解决方案看起来很理想。我安装了trelliscope 并尝试在 Windows 8 和 ubuntu 14.10 中编写代码。在每种情况下,(a) 图表均由 grViz 正确呈现 - p 是有效的。 (b) 生成的hoge.png 文件有一条错误消息abort() at (no stack trace available)。我不确定这是否是DiagrammerRtrelliscopermarkdown 的问题。从RStudio 终端提示符执行widgetThumbnail() 时也会发生同样的情况。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-02
  • 1970-01-01
  • 2015-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多