Skip to content
Prev 369699 / 398503 Next

Paths in knitr

On 08/06/2017 7:15 AM, G.Maubach at weinwolf.de wrote:
Put the path in a variable, and use that in the img tag, e.g.

```{r}
gdir <- file.path(knitr::opts_knit$get("base.dir"), "graphics")
```

<img src = `r file.path(gdir, "email_distribution_pie.png")`></img>

If you think that is still too much typing, you could make a little 
function to turn a string like "email_distribution_pie" into the fully 
specified path.

HOWEVER:  Your workflow may not be ideal.  It is almost always better to 
produce the graphs in code that's in the document, rather than in 
separate R scripts.   This makes it *much* easier to modify the plots 
and be sure that the latest version makes it into the report.

If the plots require lots of code and you think it would be distracting 
in the source of your document, then it's time to make a private 
package, and put the code in there.  In the document, just include calls 
to functions from that package.

Duncan Murdoch