我无法举出例子,否则我根本不会问这个问题。 我喜欢 R 的 reprex 包。但是,有时我会编写一些简单的 R markdown 代码,并使用 rmarkdown::render() 进行处理。有没有一种方法可以在 R markdown 文件上使用 reprex 包来生成可重现的示例,该示例很容易发布到例如本网站上?
非常感谢
您可以使用 reprex_render
包中的
reprex
函数来渲染 .R
或 .Rmd
文件。
这是 rmarkdown::render() 的包装,强制执行 “代表”心态。
这是一个可重现的示例:
reprex::reprex_render(input = "reprex_test.Rmd")
输出查看器:
示例 Rmarkdown 文件名为
reprex_test.Rmd
:
---
title: "Untitled"
output: html_document
date: "2024-02-22"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.