Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reference a previously defined object in a `knitr` Rnw chunk figure caption [duplicate]

Tags:

r

knitr

Is it possible to reference a previously defined object in a knitr Rnw chunk figure caption?

<<chunk1>>=
  myObj <- "caption"
@

<<chunk2, fig.cap="This is my \\Sexpr{myObj}">>=
  plot(1,2)
@

This SO answer shows how to use LaTeX in a figure caption, but I can't get the same idea to work with \Sexpr{} and an R object.

like image 435
Eric Green Avatar asked Oct 31 '22 13:10

Eric Green


1 Answers

@MrFlick offered a simple solution:

fig.cap=paste("This is my", myObj)

Documenting here to close the question.

like image 107
Eric Green Avatar answered Nov 09 '22 15:11

Eric Green