5

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.

Community
  • 1
  • 1
Eric Green
  • 7,385
  • 11
  • 56
  • 102

1 Answers1

2

@MrFlick offered a simple solution:

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

Documenting here to close the question.

Eric Green
  • 7,385
  • 11
  • 56
  • 102