I’ve seen a few questions about this, but can’t work out how to do what I want.
By default, Sweave creates graphics by concatenating the name of the Rnw file and the name of the graphic object label.
From this question (Make Sweave + RweaveHTML put all graphics in a specified folder) If I want all my graphics in the folder foo and to be named bar-graphic I can use
\SweaveOpts{prefix.string=foo/bar}
But how can I get the graphics in folder foo but named rnwfile-graphic ?
OK, this probably should be assigned to the innermost circle of hell, but the only way I know of to get the name of the currently running script is to use (abuse?) the source reference attached to functions. Consider this Sweave chunk in a file
foo.RnwWhen I process
foo.Rnwwith Sweave I get:You could make a dummy function at the top of your Sweave file, pull out the
$filenamefrom the source reference, and process it to remove the extension, e.g.:and then build up the string needed for
prefix.string, with saywhere
prefix.stringcontains the built up path and prefix.Here is a complete example:
that when processed by Sweave gives:
Tweak that as you see fit.