How to display verbatim inline r code with backticks using Rmarkdown?

后端 未结 5 522
广开言路
广开言路 2020-12-08 19:49

By doubling the backticks in Markdown, it is easy to render some text in code style including the backticks, such as: `r 2+2`. But how to do that with RMark

5条回答
  •  半阙折子戏
    2020-12-08 20:12

    Here is a satisfactory finding. First define the function

    rinline <- function(code){
      html <- '``` `r CODE` ```'
      sub("CODE", code, html)
    }
    

    in an invisible chunk. Then you can show `r 2+2` by typing:

    Some R code inline : `r rinline("2+2")` - nice 
    

提交回复
热议问题