Is there an R Markdown equivalent to \Sexpr{} in Sweave?

前端 未结 2 629
孤街浪徒
孤街浪徒 2020-12-08 06:37

Using R Markdown in knitr is there an equivalent to \\Sexpr{} in Sweave?

2条回答
  •  萌比男神i
    2020-12-08 07:02

    Yes. You can use

    `r your_expression_here`
    

    So something like

    2+2 is: `r 2+2`
    

    Should produce:

    2+2 is: 4
    

    I initially found it a little difficult trying to figure out what the different syntax was for each of the different styles you could use in knitr (html, markdown, sweave, ...) and resorted to looking at Yihui's minimal examples (which do a good job) but if you can read regular expressions you can view the default pattern definitions. You even have the option of defining your own syntax if you want.

提交回复
热议问题