Closed lf-araujo closed 6 years ago
Thanks, will try to create one for R and report back...
Just to clarify things. pp uses graphviz and plantuml to produce diagrams from a simple text file embedded in a markdown document. In the output, the source of the diagram is replaced by an image. I'll soon add a support for Asymptote.
R may be a bit more complex because I guess it can do much more than just producing an image.
What kind of usage would like?
In both cases it is possible to add R support. In fact you can already call R scripts as shell scripts (not tested!):
!sh
~~~~~
#!/usr/bin/Rscript --slave
....
~~~~~
Thanks,
Two functionalities:
Best, lf
Could you please give small examples (scripts and command lines) for both functionalities?
Absolutelly,
Here is a small example using knitr. The code I enter within the block gets printed at the pdf as well:
```{r lm}
model = lm(dist~speed,data = cars)
summary(model)
Produces:
Call:
lm(formula = dist ~ speed, data = cars)
Residuals:
Min 1Q Median 3Q Max
-29.069 -9.525 -2.272 9.215 43.201
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.5791 6.7584 -2.601 0.0123 *
speed 3.9324 0.4155 9.464 1.49e-12 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 15.38 on 48 degrees of freedom
Multiple R-squared: 0.6511, Adjusted R-squared: 0.6438
F-statistic: 89.57 on 1 and 48 DF, p-value: 1.49e-12
The code below is executed with knitr and printed out as a graph:
```{r pressure, echo=FALSE, fig.cap='test plot'}
plot(pressure)
Here is how it looks in the pdf:
Ok. The first example could be implemented as a script macro that calls Rscript --slave
.
The second example, called with Rscript --slave
produces a PDF file (Rplots.pdf
). Do you know how to change the name and the format of the output?
Thanks for the interest. A quick investigation and I found a possible approach. If you have R installed, send the following to bash (or run in the command line):
Rscript -e 'pdf("foo.pdf"); plot(cumsum(rnorm(100)), type="l"); dev.off()'
This will generate a foo.pdf with a nice figure that pandoc will be able to import. Other functions exists as well, but they are not in base R (png(), jpeg(), and so on)... I am almost sure pandoc can handle pdfs as figures for latex output, less sure about other formats...
UPDATE: just tested, pdf figures are accepted in latex and html, probably all non-plain text formats as well.
Rscript -e 'png("foo.png"); plot(cumsum(rnorm(100)), type="l");'
produces a PNG image.
This could be executed by a Rplot
macro:
!Rplot(foo)
~~~~
plot(cumsum(rnorm(100)), type="l");
~~~~
The Rscript
will just execute a script and print its output.
I have added both !Rscript
and !Rplot
to the last release (2.1.2):
It works on Linux (Fedora with the default R package). I can not test it on MacOS or Windows.
Thank you so much. Will test it, as soon as I can!
I will try to incorporate pp into my pandoc building system with make.
Best, lf
Tested, both work as expected in Ubuntu 17.04. Thank you.
It would be an extra if I were able to pass {width = 30%} to the figure environment as per the other issue I opened.
You may want to close this issue.
With diagrams macros you can pass the attributes with the image name:
!Rplot(IMAGE{attributes})(LEGEND)(GRAPH DESCRIPTION)
e.g.
!Rplot(img/foo{width=30%})(legend...)(R script...)
@CDSoft please close issues, whenever possible
Are there any plans for R programming language support? R allows for very complex graphic capabilities and would be a nice addition!
Thanks