Replace rmarkdown tags in inline r code

Hi there,

I want to print some regression models definitions in rmarkdown as inline code:

Model: `r modeldef`

Unfortunately, the model definition string contains two asterisks (*) as in

output ~ fact1 + fact2*fact3 + fact1*fact2

and now (of course) I get italic text fact3 + fact1 instead of the asterisks.

Is there any existing function to avoid such problems or do I have to write my own function using gsubs to covert the string before inlining it?

Thanks for your help,


There is a nice package to show equation of a model. See

Would that help you here ?

Otherwise you need to process the string to escape the character that needs to be escaped or wrap into inline code syntax

Model: `` `r modeldef` ``

to get
Model: output ~ fact1 + fact2*fact3 + fact1*fact2

1 Like

Wow, that was extremely fast, thank you very much!

Cheers, Martin

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.