rmarkdown::render 不会渲染 rgl::plot3d 图形(但 Knit 按钮可以!)

发布于 2025-01-16 04:50:13 字数 619 浏览 2 评论 0原文

请考虑以下示例:

       ---
       title: "Untitled"
       output:
         pdf_document: default
       ---

       ```{r, setup}
       Sys.setenv(CHROMOTE_CHROME = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe")
       options(rgl.useNULL = TRUE)
       rgl::setupKnitr()
       ```

       Plot:

       ```{r, rgl = TRUE, dev = "png"}
       rgl::plot3d(rnorm(10), rnorm(10), rnorm(10))
       ```

运行 rmarkdown::render("temp.Rmd", output_format = "pdf_document") 会生成没有图形的 PDF。更有趣的是,点击 RStudio 中的 Knit 按钮会生成完美的 PDF! (这本身很奇怪;我的印象是 Knit 按钮与上面的调用完全相同。)

Consider the following example:

       ---
       title: "Untitled"
       output:
         pdf_document: default
       ---

       ```{r, setup}
       Sys.setenv(CHROMOTE_CHROME = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe")
       options(rgl.useNULL = TRUE)
       rgl::setupKnitr()
       ```

       Plot:

       ```{r, rgl = TRUE, dev = "png"}
       rgl::plot3d(rnorm(10), rnorm(10), rnorm(10))
       ```

Running rmarkdown::render("temp.Rmd", output_format = "pdf_document") produces a PDF with no figure. Even more interestingly, hitting the Knit button in RStudio produces a perfect PDF! (Which is quite strange itself; I was under the impression that the Knit button is exactly the same as the above call.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑红尘 2025-01-23 04:50:13

使用 rgl = TRUEhook_rgl 函数配合使用,这是在 knitr 中处理 rgl 的旧方法之一。它总是存在问题,因此最近的版本推荐了其他方法。

使用 rgl::setupKnit(autoprint = TRUE) 是最简单的一种。它近似于基本绘图的行为:不会出现对绘图的细微更新,仅显示最终版本。如果您不希望这样,则可以将其保留为 autoprint = FALSE,并显式包含 rglwidget() 调用以显示绘图。

自动打印并不完美,例如,一些生成 rgl 图的包不会以触发它的方式生成输出。您可以在 ?rgl::setupKnit 帮助主题中阅读有关此内容的更多信息。

Using rgl = TRUE works with the hook_rgl function, which is one of the older ways of handling rgl in knitr. It was always problematic, so recent releases have recommended other approaches instead.

Using rgl::setupKnitr(autoprint = TRUE) is the easiest one. It approximates the behaviour of base plotting: minor updates to a plot won't appear, only the final version is shown. If you don't want that, then you can leave it with autoprint = FALSE, and explicitly include rglwidget() calls to get a plot to appear.

The auto-printing isn't perfect, e.g. some packages that produce rgl plots don't produce output in a way that will trigger it. You can read more about this in the ?rgl::setupKnitr help topic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文