knitr :: is_word_output()来检查当前输出类型是否为单词–就像knitr :: is_latex_output()和knitr :: is_html_output()一样 [英] knitr::is_word_output() to check if the current output type is word – just like knitr::is_latex_output() and knitr::is_html_output()

查看:88
本文介绍了knitr :: is_word_output()来检查当前输出类型是否为单词–就像knitr :: is_latex_output()和knitr :: is_html_output()一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

knitr::is_latex_output()knitr::is_html_output()允许检查当前输出类型是否为 LaTex或HTML .

knitr::is_latex_output() and knitr::is_html_output() allow checking if the current output type LaTex or HTML respectively.

Word是否有等效的输出格式?

Is there an equivalent for Word as an output format?

如果没有,最简单的解决方法是什么?

If not, what would be the most simple to use workaround?

---
title: "MWE for different file formats in namespace:knitr"
output:
  pdf_document: default
  html_document: default
  word_document: default
---

```{r}
if (knitr::is_html_output()) {
  cat("HTML") 
  }
if (knitr::is_latex_output()) {
  cat("LATEX") 
  }
if (knitr::is_word_output()) {
  cat("WORD")
}
## Error: 'is_word_output' is not an exported object from 'namespace:knitr'
```

推荐答案

您可以使用内部knitr函数获取所需的类型:

You can use a internal knitr function to get the type you want::

is_word_output <- function(fmt = knitr:::pandoc_to()) {
  length(fmt) == 1 && fmt == "docx"
}

这篇关于knitr :: is_word_output()来检查当前输出类型是否为单词–就像knitr :: is_latex_output()和knitr :: is_html_output()一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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