To have R chunk in line with text using knitr

前端 未结 2 499
Happy的楠姐
Happy的楠姐 2021-01-26 03:17

How to have R code (R chunk) inline with my text?

Example:

Please install the package by using install.packages(\"ISwR\")

wher

相关标签:
2条回答
  • 2021-01-26 03:36

    Following a suggestion from Yihui,

    \documentclass{article} 
    <<setup, include=FALSE>>= 
    knit_hooks$set(inline = function(x) { 
      if (is.numeric(x)) return(knitr:::format_sci(x, 'latex')) 
      knitr:::hi_latex(x) 
    }) 
    @ 
    \begin{document} 
    
    Please install the package by using \Sexpr{'install.packages("ISwR")'}. 
    
    \end{document} 
    
    0 讨论(0)
  • 2021-01-26 03:39

    You can use the 3 backticks ``` if you want the encapsulated code NOT to be executed inline . E.g.

    There were ```nrow(cars)``` cars studied
    
    0 讨论(0)
提交回复
热议问题