【问题标题】:R: Correctly Using the "rmarkdown::render()" FunctionR:正确使用“rmarkdown::render()”函数
【发布时间】:2023-02-05 19:08:08
【问题描述】:

我正在使用 R 编程语言。

我的问题:我正在尝试学习如何在 R 中使用 rmarkdown::render() 函数。

例如,假设我有以下 R Markdown 代码:

---
title: "Storyboard Commentary"
output: 
  flexdashboard::flex_dashboard:
    storyboard: true
---

### A nice scatterplot here

```{r}
plot(cars, pch = 20)
grid()
```

---

Some commentary about Frame 1.

### A beautiful histogram on this board

```{r}
hist(faithful$eruptions, col = 'gray', border = 'white', main = '')
```

---

Some commentary about Frame 2.

我将上面的代码复制并粘贴到一个记事本文档中——然后将该文件另存为“test_render.Rmd”。

现在,我想使用 render() 函数来执行这个文件,例如rmarkdown::render("test_render.Rmd") - 但我不确定如何将此文件导入 R使用代码(即无需手动单击/指向文件)。

我问这个问题的原因是因为我在学校使用的计算机只有较旧的 R GUI 版本(即我们没有 R Studio),我想直接将 .Rmd 文件导入 R 和使用此 render() 函数,并创建最终结果。

有人可以告诉我该怎么做吗?

谢谢!

【问题讨论】:

  • 您是否在 R 控制台上执行了 rmarkdown::render("test_render.Rmd") 并验证了输出的 html 文件(我认为文件名应该是 test_render.html)是否存在于您当前的工作目录中?

标签: r


【解决方案1】:

您应该能够渲染 rmarkdown 文件并使用渲染的输入和输出参数导出它,即

rmarkdown::render(input = "test_render.Rmd", output_file = "test_render.html")

它应该保存在您当前的工作目录中。

【讨论】:

  • @smackington:非常感谢!这奏效了!
猜你喜欢
  • 1970-01-01
  • 2022-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-14
  • 2018-09-05
  • 2021-11-09
  • 2021-06-15
相关资源
最近更新 更多