gpt4 book ai didi

r - 使用R包详细信息显示R输出和代码

转载 作者:行者123 更新时间:2023-12-04 12:03:40 25 4
gpt4 key购买 nike

我想将R包details用于Markdown和包文档的创建详细信息HTML标签。我的工作示例如下:

---
title: "Customizing Details"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{custom}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

```{r setup, echo = FALSE}
library(details)
```


### Open

```{r ch1, echo = TRUE}
seq(from = 1, to = 10, by = 2) %>%
details::details(
summary = "Output",
open = TRUE
)
```


```{r}
details(
plot(x=mtcars$mpg,y=mtcars$wt),
summary = "Output",
imgur = FALSE,
open = TRUE
)
```


它工作正常。但是,我想先显示输出,然后显示隐藏的代码,而不显示 details包的其他代码。有什么想法请。

enter image description here

最佳答案

我认为您只需要更改块选择:

ch1具有echo = FALSE,因此不显示代码,仅显示对象。
ch2的echo = TRUE,结果='hide',因此结果被隐藏,但显示了输出。
与ch3和ch4相同。

```{r ch1, echo = FALSE}
var <- seq(from = 1, to = 10, by = 2) %>%
details::details(
summary = "Output",
open = TRUE
)
var
```


这是您显示代码的位置:

```{r ch2, echo = TRUE, results = 'hide'}
seq(from = 1, to = 10, by = 2) %>%
details::details(
summary = "Output",
open = TRUE
)
```


这是绘制图形的位置:

```{r ch3, echo = FALSE}
p <- details(
plot(x=mtcars$mpg,y=mtcars$wt),
summary = "Output",
imgur = FALSE,
open = TRUE
)
p
```


这是您显示代码的位置:

```{r ch4, results = 'hide'}
details(
plot(x=mtcars$mpg,y=mtcars$wt),
summary = "Output",
imgur = FALSE,
open = TRUE
)

```

关于r - 使用R包详细信息显示R输出和代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60708343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com