I use knitrto create reports. However, I often first prepare "internal" documents that contain all the graphs, and then for the final report or paper I want to include only some numbers.
Let's say I have a set of systematically created shapes, let's say I iterate over my instance:
<<sample, fig.keep = 'all'>>=
specimen <- c("436a", "783a", "10b")
for (s in specimen)
plot (results [s])
@
This will create multiple files figures/sample1.pdf, figures/sample2.pdfetc. Although numbering with 1, 2, ... is good for a report created by a scratch, if I want to include one of the graphs in a document, it is cumbersome and error prone to figure out which .pdf belongs to which sample.
How can I say knitruse file names for example "figures/sample-436a.pdf"?
I tried <<fig.path = sprintf ("figures/sample-%s", s)>>=, but it does not work: sit is unknown, so I think it fig.pathis evaluated at the beginning of fragment processing, and not when saving the fragment.
PS: One obvious way to reduce the risk of mistakes is to name them, but IMHO they are ugly in paper.
source
share