-
-
Save daroczig/5238455 to your computer and use it in GitHub Desktop.
## load "pander" package | |
## http://rapporter.github.com/pander/ | |
library(pander) | |
## "brew" the below file to Pandoc's markdown | |
Pandoc.brew('example.brew') | |
## or convert to HTML at one go | |
## NOTE: `pandoc` is needed for the conversion | |
Pandoc.brew('example.brew', output = tempfile(), convert = 'html') | |
## or pdf/docx/odt | |
Pandoc.brew('example.brew', output = tempfile(), convert = 'pdf') | |
Pandoc.brew('example.brew', output = tempfile(), convert = 'docx') | |
Pandoc.brew('example.brew', output = tempfile(), convert = 'odt') |
# Doc header 1 | |
Some text explaining the analysis we are doing | |
<%= | |
summary(cars)# a summary table | |
%> | |
Images should be in separate chunks not to be handles as inline image: | |
<%= | |
plot(cars) # a plot | |
%> | |
And a model at last: | |
<%= | |
fit <- lm(dist~speed, data = cars) | |
fit | |
%> |
# Doc header 1 | |
Some text explaining the analysis we are doing | |
---------------------------------- | |
speed dist | |
------ ------------ -------------- | |
**** Min. : 4.0 Min. : 2.00 | |
**** 1st Qu.:12.0 1st Qu.: 26.00 | |
**** Median :15.0 Median : 36.00 | |
**** Mean :15.4 Mean : 42.98 | |
**** 3rd Qu.:19.0 3rd Qu.: 56.00 | |
**** Max. :25.0 Max. :120.00 | |
---------------------------------- | |
Images should be in separate chunks not to be handles as inline image: | |
![](/tmp/RtmpD3QXAs/plots/4304da6127c.png) | |
And a model at last: | |
-------------------------------------------------------------- | |
Estimate Std. Error t value Pr(>|t|) | |
----------------- ---------- ------------ --------- ---------- | |
**(Intercept)** -17.58 6.758 -2.601 0.01232 | |
**speed** 3.932 0.4155 9.464 1.49e-12 | |
-------------------------------------------------------------- | |
Table: Fitting linear model: dist ~ speed |
Thanks @eipi10 for the bug report, that's definitely a bug in pander
it seems. There is a command in Pandoc.brew
[L134] where I try to remove absolute path from the generated image tags and your pretty strange basedir
produces a screwed up regular expression there. BTW is it normal to have a folder like /var/folders/Yq/YqZGRlFzE9yM-RL+qDXd0U+++TI/-Tmp-//RtmpTWO4zs/
on OSX?
Anyway, I will fix that on the GitHub version soon (in 24 hours), I promise. Thanks again!
Thanks for the quick reply @daroczig. The weird directory is (AFAIK) a temporary (hidden) folder that OS-X creates in some download situations. I don't really know the details, but it does that in a wide range of situations, such as when installing an R package. For example, here's the output of a command I just ran in the R console:
> install.packages('ggplot2')
Installing package(s) into ‘/Users/eipi10/Library/R/2.15/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.cnr.Berkeley.edu/bin/macosx/leopard/contrib/2.15/ggplot2_0.9.3.1.tgz'
Content type 'application/x-gzip' length 2659920 bytes (2.5 Mb)
opened URL
==================================================
downloaded 2.5 Mb
The downloaded binary packages are in
/var/folders/Yq/YqZGRlFzE9yM-RL+qDXd0U+++TI/-Tmp-//RtmpTWO4zs/downloaded_packages`
I'm not sure why it works that way and I've never had a reason to try and find anything on those weird paths, but that's the way it seems to work.
eipi10
Yeah, that's pretty normal after all it seems, I am just curious why this problem did not occurred recently.
Anyway, IMHO it's fixed in the GitHub version. Could you please verify, @eipi10?
Works fine now. Thanks very much for creating and maintaining pander!
Daroczig,
I'm new to the R/markdown/pandoc/knitr continuum and used your example to try to learn how to convert R Markdown files into MS-Word files. (Why would I want to do that, you ask? Well, my colleagues insist on using Word.) However, I ran into an error. The command
Pandoc.brew('example.brew')
ran just fine. But all of the next commands specifying output to html, docx, etc. produced the following error in theR console:
Error in gsub(sprintf("]\\(%s/", basedir), "]\\(", res) : invalid regular expression ']\(/var/folders/Yq/YqZGRlFzE9yM-RL+qDXd0U+++TI/-Tmp-//RtmpTWO4zs/', reason 'Invalid use of repetition operators'
I get the same error even if the 'example.brew' file contains just a single sentence of plain text. I'm hoping you might know what's causing the problem. In case it might help, here's my R sessionInfo:
locale:
en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
stats, graphics, grDevices, utils, datasets, methods and base
other attached packages:
knitr_1.1, pander_0.3.1, stringr_0.6.2, foreign_0.8-52, reshape2_1.2.2, car_2.0-16, nnet_7.3-5, MASS_7.3-23 and slidify_0.3.3
loaded via a namespace (and not attached):
digest_0.6.3, evaluate_0.4.3, formatR_0.7, markdown_0.5.4, plyr_1.8, tools_2.15.1, whisker_0.1 and yaml_2.1.7
Thanks for any suggestions you might have.
eipi10