inline_expr: Wrap code using the inline R expression syntax

Description Usage Arguments Value Examples

View source: R/parser.R

Description

This is a convenience function to write the "source code" of inline R expressions. For example, if you want to write `r 1+1` literally in an R Markdown document, you may write `` `r knitr::inline_expr('1+1')` ``; for Rnw documents, this may be \verb|\Sexpr{knitr::inline_expr{'1+1'}}|.

Usage

1
inline_expr(code, syntax)

Arguments

code

Character string of the inline R source code.

syntax

A character string to specify the syntax, e.g. rnw, html, or md. If not specified, this will be guessed from the knitting context.

Value

A character string marked up using the inline R code syntax.

Examples

1
2
3
4
library(knitr)
inline_expr("1+1", "rnw")
inline_expr("1+1", "html")
inline_expr("1+1", "md")

Example output

[1] "\\Sexpr{1+1}"
[1] "<!--rinline 1+1 -->"
[1] "`r 1+1`"

knitr documentation built on Jan. 27, 2021, 5:09 p.m.