Changes

Jump to navigation Jump to search
R is a language and environment for statistical computing and graphics [http://www.r-project.org (see here)] . <br/>
RPy is a very simple, yet robust, Python interface to the R Programming Language [http://rpy.sourceforge.net] . <br/>
<texcode> \startluacodefunction testR(samplesAs example,outpdf,w,h,kernel) require("python") testR = python.import("test-R") dens = testR.densitylet's try to plot a discrete distribution of probability for a set of pseudorandom number (around 100000 samples,outpdf,w,h,kernel) dens.run()end\stopluacode \def\plotdenstiy[#1]{%\getparameters[R][#1]%\expanded{\ctxlua{testR("\Rsamples","\Routpdf",\Rwidth,\Rheight,"\Rkernel")}}%} \starttext\startTEXpage\plotdenstiy[samples={u-random-int},outpdf={test-001.pdf},width={10},height={7},kernel={o}]\setupcombinations[location=top]\startcombination[2*1]{\vbox{\hsize=7in\ssd This is a density plot of around {\tt 100 000} random numbers between $0$ and $2^{16}-1$ generated from {\tt /dev/urandom}}}{}{\externalfigure[test-001.pdf]}{}\stopcombination\stopTEXpage\stoptext</texcode> 
<pre>
import rpy2.robjects as robjects
 
<texcode>
\startluacode
function testR(samples,outpdf,w,h,kernel)
require("python")
testR = python.import("test-R")
dens = testR.density(samples,outpdf,w,h,kernel)
dens.run()
end
\stopluacode
 
\def\plotdenstiy[#1]{%
\getparameters[R][#1]%
\expanded{\ctxlua{testR("\Rsamples","\Routpdf",\Rwidth,\Rheight,"\Rkernel")}}%
}
 
\starttext
\startTEXpage
\plotdenstiy[samples={u-random-int},outpdf={test-001.pdf},width={10},height={7},kernel={o}]
\setupcombinations[location=top]
\startcombination[2*1]
{\vbox{\hsize=7in\ssd
 
This is a density plot of around {\tt 100 000} random numbers between $0$ and $2^{16}-1$ generated from {\tt /dev/urandom}}}{}
{\externalfigure[test-001.pdf]}{}
\stopcombination
\stopTEXpage
\stoptext
</texcode>
 
And here is the plot
<!--[[Image:TestPIL.jpg]]-->

Navigation menu