正如@Yihui 的R Markdown Cookbook中的4.7 Verbatim 代码块所示,我们可以在 RMarkdown 的输出中显示逐字内联表达式,
例如。但是,这将无法解析带有双引号的代码,例如
. 那么,当我想逐字演示包含这种特殊字符的内容时,我应该怎么做呢?`r knitr::inline_expr("coef(summary(model))")`
knitr::inline_expr()
`r knitr::inline_expr("coef(summary(model))["(Intercept)", "Estimate"]")`
---
title: "Untitled"
author: "CLRR"
date: "2020/6/20"
documentclass: article
output:
bookdown::pdf_document2:
latex_engine: xelatex
keep_tex: TRUE
---
This verbatim can appear in the output:
`` `r knitr::inline_expr("coef(summary(model))")` ``
<!--
But, if the code contains `"`, the evaluation fails.
`r knitr::inline_expr("coef(summary(model))["(Intercept)", "Estimate"]")`
```
Quitting from lines 2-16 (test.Rmd)
Error in parse(text = code, keep.source = FALSE) :
<text>:1:54: unexpected string constant
1: knitr::inline_expr("coef(summary(model))["(Intercept)", "
^
Calls: <Anonymous> ... hook_eval -> withVisible -> eval -> parse_only -> parse
Execution halted
```
-->