[R] Paths in knitr
G.Maubach at weinwolf.de
G.Maubach at weinwolf.de
Mon Jun 12 09:24:48 CEST 2017
Hi Yihui,
Hi Duncan,
I corrected my typo. Unfortunately knitr did not find my plots in the
directory where they reside which is different from the Rmd document.
The documentation of knitr says:
base.dir: (NULL) an absolute directory under which the plots are generate
root.dir: (NULL) the root directory when evaluating code chunks; if NULL,
the directory of the input document will be used
>From that description I thought, if the base.dir can be used for writng
plots, it is then also used for reading plots if set? No, it is not.
If I set the root directory to the plots/graphics directory will knitr
then find my plots? No, it does not.
Reading blog posts my thoughts looked not so strange to me, e.g.
https://philmikejones.wordpress.com/2015/05/20/set-root-directory-knitr/.
Unfortunately, it does not work for me.
I am using a RStudio project file. Could it be that this interferes which
the knitr options?
I tried the solution that Duncan suggested:
c_path_plots <-
"H:/2017/Analysen/Kundenzufriedenheit/Auswertung/results/graphics
`r knitr::include_graphics(file.path(c_path_plots,
"email_distribution_pie.png"))`
This solution works fine. I will go with it for this project as I have to
finish my report soon.
I read Hadley's book on bulding R Packages (
https://www.amazon.de/R-Packages-Hadley-Wickham/dp/1491910593) and found
it quite complicated and time consuming to build one. Thus I did not try
yet to build my own packages. At the end of last week I heard from another
library (http://reaktanz.de/R/pckg/roxyPackage/) which shall make building
packages much easier. I plan to try that shortly.
On my path to become better in analytics using R, I will try to use
modules of Rmd files which can then easily be integrated into a Rmd
report. I have yet to see how I can include these file into a complete
report.
Kind regards
Georg
----- Weitergeleitet von Georg Maubach/WWBO/WW/HAW am 12.06.2017 08:47
-----
Von: Yihui Xie <xie at yihui.name>
An: G.Maubach at gmx.de,
Kopie: R Help <r-help at r-project.org>
Datum: 09.06.2017 20:53
Betreff: Re: [R] Paths in knitr
Gesendet von: "R-help" <r-help-bounces at r-project.org>
I'd say it is an expert-only option. If you do not understand what it
means, I strongly recommend you not to set it.
Similarly, you set the root_dir option and I don't know why you did it,
but
it is a typo anyway (should be root.dir).
Regards,
Yihui
--
https://yihui.name
On Fri, Jun 9, 2017 at 4:50 AM, <G.Maubach at gmx.de> wrote:
> Hi Yi,
>
> many thanks for your reply.
>
> Why I do have to se the base.dir option? Cause, to me it is not clear
from
> the documentation, where knitr looks for data files and how I can adjust
> knitr to tell it where to look. base.dir was a try, but did not work.
>
> Can you give me a hint where I can find information/documentation on
this
> path issue?
>
> Kind regards
>
> Georg
>
>
> > Gesendet: Donnerstag, 08. Juni 2017 um 15:05 Uhr
> > Von: "Yihui Xie" <xie at yihui.name>
> > An: G.Maubach at weinwolf.de
> > Cc: "R Help" <r-help at r-project.org>
> > Betreff: Re: [R] Paths in knitr
> >
> > Why do you have to set the base.dir option?
> >
> > Regards,
> > Yihui
> > --
> > https://yihui.name
> >
> >
> > On Thu, Jun 8, 2017 at 6:15 AM, <G.Maubach at weinwolf.de> wrote:
> > > Hi All,
> > >
> > > I have to compile a report for the management and decided to use
> RMarkdown
> > > and knitr. I compiled all needed plots (using separate R scripts)
> before
> > > compiling the report, thus all plots reside in my graphics
directory.
> The
> > > RMarkdown report needs to access these files. I have defined
> > >
> > > ```{r setup, include = FALSE}
> > > knitr::opts_knit$set(
> > > echo = FALSE,
> > > xtable.type = "html",
> > > base.dir = "H:/2017/Analysen/Kundenzufriedenheit/Auswertung",
> > > root_dir = "H:/2017/Analysen/Kundenzufriedenheit/Auswertung",
> > > fig.path = "results/graphics") # relative path required, see
> > > http://yihui.name/knitr/options
> > > ```
> > >
> > > and then referenced my plot using
> > >
> > > <img src = "email_distribution_pie.png"></img>
> > >
> > > because I want to be able to customize the plotting attributes.
> > >
> > > But that fails with the message "pandoc.exe: Could not fetch
> > > email_distribution_pie.png".
> > >
> > > If I give it the absolute path
> > > "H:/2017/Analysen/Kundenzufriedenheit/Auswertung/results/
> graphics/email_distribution_pie.png"
> > > it works fine as well if I copy the plot into the directory where
the
> > > report.RMD file resides.
> > >
> > > How can I tell knitr to fetch the ready-made plots from the graphics
> > > directory?
> > >
> > > Kind regards
> > >
> > > Georg
>
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list