根据knitr的输出格式评估块 [英] Evaluate a Chunk based on the output format of knitr

查看:77
本文介绍了根据knitr的输出格式评估块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用Markdown的初学者(我在R studio和 针织物.)

I am a beginner in using Markdown (I am using it with R studio and knitr).

我正在努力争取希望您能够为我提供帮助 弄清楚.

I am struggling with a point that I hope you would be able to help me to figure it out.

仅当rmarkdown文档的output_format为pdf时,我希望对块进行评估.换句话说,如果将编织输出选择为编织PDF",则块选项"eval"将自动设置为TRUE.否则,eval = FALSE.

I would like a chunk to be evaluated only if the output_format of the rmarkdown document is pdf. In other words, the chunk option "eval" automatically set to TRUE if the knitr output was selected as "knitr PDF". Otherwise, eval = FALSE.

您认为最简单的方法是这样做.

In your view, what is the most straightforward way to do this.

非常感谢

推荐答案

尝试一下:

```{r eval = knitr::is_latex_output()}
"Hi, I'm in a PDF!"
```

或者,仅在不将其渲染为PDF时评估块:

Or, to evaluate chunks only when you're not rendering to PDF:

```{r eval = !knitr::is_latex_output()}
"Hi, I'm not in a PDF!"
```

这篇关于根据knitr的输出格式评估块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆