evaluate inline code in string

Hello everyone,
I'm creating automated exams in markdown and I was wondering, whether there is a way to evaluate knitr inline code in knitr chunk. I have external dataset with various exam introductions, and I randomly load one of them. Because the introductions will be written by collegues without knowledge of R, I wanted to use inline code, as it is easy to inderstand.

I have following chunk


where the intro_str is load from file, for example to something like this
intro_str=In the research, there were r n subjects recruited.

Where the n is value defined in the markdown script

I know that I can do something like


and redefine intro_str to be something like

intro_str <- "sprintf('In the research, there were %d subjects recruited. ',n)"

But when the intro_str gets more complicated, the traditional eval way would be too complicated to write for others

Is there a function .in knitr that can evaluate inline code in string?


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