Here is a trick that I use. First, note x60
is `
:
> cat('x60', '
')
`
Then you write
`r 'x60r foo+barx60'`
which will give you `r foo+bar`
in the markdown output, but that will become r foo+bar
in the HTML output, so you need to protect the backticks in markdown, using two (or more) backticks. Then you end up with this hairball:
`` `r 'x60r foo+barx60'` ``
Your own solution is good, but I'd just define
rinline <- function(code) {
sprintf('``` `r %s` ```', code)
}
Also see this post for another trick.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…