| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/brew.R |
| 3 |
\name{Pandoc.brew} |
| 4 |
\alias{Pandoc.brew} |
| 5 |
\title{Brew in pandoc format} |
| 6 |
\usage{ |
| 7 |
Pandoc.brew( |
| 8 |
file = stdin(), |
| 9 |
output = stdout(), |
| 10 |
convert = FALSE, |
| 11 |
open = TRUE, |
| 12 |
graph.name, |
| 13 |
graph.dir, |
| 14 |
graph.hi.res = FALSE, |
| 15 |
text = NULL, |
| 16 |
envir = parent.frame(), |
| 17 |
append = FALSE, |
| 18 |
... |
| 19 |
) |
| 20 |
} |
| 21 |
\arguments{ |
| 22 |
\item{file}{file path of the brew template. As this is passed to \code{readLines}, \code{file} could be an URL too, but not over SSL (for that latter \code{RCurl} would be needed).} |
| 23 |
|
| 24 |
\item{output}{(optional) file path of the output file} |
| 25 |
|
| 26 |
\item{convert}{string: format of required output document (besides Pandoc's markdown). Pandoc is called if set via \code{Pandoc.convert} and the converted document could be also opened automatically (see below).} |
| 27 |
|
| 28 |
\item{open}{try to open converted document with operating system's default program} |
| 29 |
|
| 30 |
\item{graph.name}{character string (default to \code{\%t} when \code{output} is set to \code{stdout} and \code{paste0(basename(output), '-\%n')} otherwise) passed to \code{\link{evals}}. Besides \code{\link{evals}}'s possible tags \code{\%i} is also available which would be replaced by the chunk number (and optionally an integer which would handle nested \code{brew} calls) and \code{\%I} with the order of the current expression.} |
| 31 |
|
| 32 |
\item{graph.dir}{character string (default to \code{tempdir()} when \code{output} is set to \code{stdout} and \code{dirname(graph.name)} otherwise) passed to \code{\link{evals}}} |
| 33 |
|
| 34 |
\item{graph.hi.res}{render high resolution images of plots? Default is \code{FALSE} except for HTML output.} |
| 35 |
|
| 36 |
\item{text}{character vector (treated as the content of the \code{file}} |
| 37 |
|
| 38 |
\item{envir}{environment where to \code{brew} the template} |
| 39 |
|
| 40 |
\item{append}{should append or rather overwrite (default) the \code{output} markdown text file? Please note that this option only affects the markdown file and not the optionally created other formats.} |
| 41 |
|
| 42 |
\item{...}{additional parameters passed to \code{\link{Pandoc.convert}}} |
| 43 |
} |
| 44 |
\value{ |
| 45 |
converted file name with full path if \code{convert} is set, none otherwise |
| 46 |
} |
| 47 |
\description{ |
| 48 |
This function behaves just like \code{brew} except for the \code{<\%=...\%>} tags, where \code{Pandoc.brew} first translate the R object found between the tags to Pandoc's markdown before passing to the \code{cat} function. |
| 49 |
} |
| 50 |
\details{ |
| 51 |
This parser tries to be smart in some ways: |
| 52 |
|
| 53 |
\itemize{ |
| 54 |
\item a block (R commands between the tags) could return any value at any part of the block and there are no restrictions about the number of returned R objects |
| 55 |
\item plots and images are grabbed in the document, rendered to a png file and \code{pander} method would result in a Pandoc's markdown formatted image link (so the image would be shown/included in the exported document). The images are put in \code{plots} directory in current \code{getwd()} or to the specified \code{output} file's directory. |
| 56 |
\item all warnings/messages and errors are recorded in the blocks and returned in the document as a footnote |
| 57 |
} |
| 58 |
|
| 59 |
Please see my Github page for details (\url{https://rapporter.github.io/pander/#brew-to-pandoc}) and examples (\url{https://rapporter.github.io/pander/#examples}). |
| 60 |
} |
| 61 |
\note{ |
| 62 |
Only one of the input parameters (\code{file} or \code{text}) is to be used at once! |
| 63 |
} |
| 64 |
\examples{ |
| 65 |
\dontrun{ |
| 66 |
text <- paste('# Header', '', |
| 67 |
'What a lovely list:\n<\%=as.list(runif(10))\%>', |
| 68 |
'A wide table:\n<\%=mtcars[1:3, ]\%>', |
| 69 |
'And a nice chart:\n\n<\%=plot(1:10)\%>', sep = '\n') |
| 70 |
Pandoc.brew(text = text) |
| 71 |
Pandoc.brew(text = text, output = tempfile(), convert = 'html') |
| 72 |
Pandoc.brew(text = text, output = tempfile(), convert = 'pdf') |
| 73 |
|
| 74 |
## pi is awesome |
| 75 |
Pandoc.brew(text='<\%for (i in 1:5) {\%>\n Pi has a lot (<\%=i\%>) of power: <\%=pi^i\%><\%}\%>') |
| 76 |
|
| 77 |
## package bundled examples |
| 78 |
Pandoc.brew(system.file('examples/minimal.brew', package='pander')) |
| 79 |
Pandoc.brew(system.file('examples/minimal.brew', package='pander'), |
| 80 |
output = tempfile(), convert = 'html') |
| 81 |
Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander')) |
| 82 |
Pandoc.brew(system.file('examples/short-code-long-report.brew', package='pander'), |
| 83 |
output = tempfile(), convert = 'html') |
| 84 |
|
| 85 |
## brew returning R objects |
| 86 |
str(Pandoc.brew(text='Pi equals to <\%=pi\%>. |
| 87 |
And here are some random data:\n<\%=runif(10)\%>')) |
| 88 |
|
| 89 |
str(Pandoc.brew(text='# Header <\%=1\%>\nPi is <\%=pi\%> which is smaller then <\%=2\%>. |
| 90 |
foo\nbar\n <\%=3\%>\n<\%=mtcars[1:2,]\%>')) |
| 91 |
|
| 92 |
str(Pandoc.brew(text='<\%for (i in 1:5) {\%> |
| 93 |
Pi has a lot (<\%=i\%>) of power: <\%=pi^i\%><\%}\%>')) |
| 94 |
} |
| 95 |
} |
| 96 |
\references{ |
| 97 |
\itemize{ |
| 98 |
\item Jeffrey Horner (2011). _brew: Templating Framework for Report Generation._ \url{https://cran.r-project.org/package=brew} |
| 99 |
\item John MacFarlane (2012): _Pandoc User's Guide_. \url{https://johnmacfarlane.net/pandoc/README.html} |
| 100 |
} |
| 101 |
} |