R Extension for MediaWiki v0.12/Examples

Aus sk21
Wechseln zu: Navigation, Suche
 InstallationDocumentationHelpExamples

Generally you see under Edit view how it looks if you edit the wiki page whereas Page view shows the result displayed to the reader of the wiki page.

Note that some combinations of options may not work as expected:

output="wiki" and using either iframe or echo
will immediately create an error
name="xyz" and not using iframe.
if linked with interaction then either nothing will happen or a new window with an error message is opened

R

R - Raw output

simple
Edit view
<R>1:10</R>
Page view RExample1.png
with echoing
Edit view
<R echo>1:10</R>
Page view RExample8.png
with echoing and iframe
Edit view
<R iframe="width:100%;height:50px" echo>1:10</R>
Page view RExample9.png
using outMatrix
Edit view
<R>
prob=0.15; nmin=1; nmax=15; x=6
m <-pbinom(rep(0:x, nmax-nmin+1), rep(nmin:nmax,x), prob)
dim(m) <- c(nmax-nmin+1,x+1)
m <- t(m)
colnames(m) <- format(nmin:nmax)
rownames(m) <- format(0:x)
outMatrix(m, title='x-n', format=list(numeric='%.4f'))
</R>
Page view 012 R raw outMatrix.png

R - HTML output

simple using outMatrix
Edit view
<R output="html">
prob=0.15; nmin=1; nmax=15; x=6
m <-pbinom(rep(0:x, nmax-nmin+1), rep(nmin:nmax,x), prob)
dim(m) <- c(nmax-nmin+1,x+1)
m <- t(m)
colnames(m) <- format(nmin:nmax)
rownames(m) <- format(0:x)
outMatrix(m, title='x-n', format=list(numeric='%.4f'))
</R>
Page view 012 R html outMatrix.png
with echoing and iframe using outMatrix
Edit view
<R output="html" iframe="width:100%;height:250px;" echo>
prob=0.15; nmin=1; nmax=15; x=6
m <-pbinom(rep(0:x, nmax-nmin+1), rep(nmin:nmax,x), prob)
dim(m) <- c(nmax-nmin+1,x+1)
m <- t(m)
colnames(m) <- format(nmin:nmax)
rownames(m) <- format(0:x)
outMatrix(m, title='x-n', format=list(numeric='%.4f'))
</R>
Page view 012 R html iframe outMatrix.png

R - Graphics output

simple
Edit view
<R output="display">
pdf(rpdf, width=3, height=3)
plot(1:10, 1:10)
</R>
Page view RExample13.png

R - Mixed output

simple
Edit view
<R>
t <- 1:10
t
pdf(rpdf, width=3, height=3)
plot(t,t)
dev.off()
-t
pdf(rpdf, width=3, height=3)
plot(t,-t)
dev.off()
</R>
Page view RExample16.png

R - Wiki output

simple using outMatrix
Edit view
<R output="wiki">
x<-matrix(1:12,ncol=3)
rownames(x) <- sprintf("row %i", 1:4)
colnames(x) <- sprintf("col %i", 1:3)
outMatrix(x, title="x")
</R>
Page view 012 R wiki outMatrix.png
simple and echoing with using outMatrix
Edit view
<R output="wiki" echo>
x<-matrix(1:12,ncol=3)
rownames(x) <- sprintf("row %i", 1:4)
colnames(x) <- sprintf("col %i", 1:3)
outMatrix(x, title="x")
</R>
Page view 012 R wiki echo outMatrix.png

R - Interaction

simple
Edit view
<Rform name="test1">
from: <Rinput name="from" type="text" size="5" value="1" /> 
to: <Rinput name="to" type="text" size="5" value="10" /> 
<Rinput type="submit" value=" Submit " />  
</Rform>

<R  name="test1">
if (exists("from")) from <- as.numeric(from) else from <- 1
if (exists("to")) to <- as.numeric(to) else to <- 10
from:to
</R>
Page view displays a result first, but after pressing the Submit button of the form in a new window will appear with
012 R interaction.png
simple using iframe
Edit view
<Rform name="test3">
from: <Rinput name="from" type="text" size="5" value="1" /> 
to: <Rinput name="to" type="text" size="5" value="10" /> 
<Rinput type="submit" value=" Submit " />  
</Rform> 
<R  name="test3"  iframe="width:100%;height:150px" echo>
if (exists("from")) from <- as.numeric(from) else from <- 1
if (exists("to")) to <- as.numeric(to) else to <- 10
from:to 
</R>
Page view 012 R interaction iframe.png

Octave

Octave - Raw output

simple
Edit view
<M>1:10</M>
Page view 012 Octave raw.png
with echoing
Edit view
<M echo>1:10</M>
Page view 012 Octave raw echo.png
with echoing and iframe
Edit view
<M iframe="width:100%;height:50px" echo>1:10</M>
Page view 012 Octave raw echo iframe.png
using outMatrix
Edit view
<M>
x=magic(5);
outMatrix(x, "title", "magic(5)", "format.numeric", "%.0f")
</M>
Page view 012 Octave outMatrix.png

Octave - HTML output

simple
Edit view
<M output="html">
x=magic(5);
outMatrix(x, "title", "magic(5)", "format.numeric", "%.0f")
</M>
Page view 012 Octave html outMatrix.png

Octave - Graphics output

simple
Edit view
<M>
set (0, "defaultlinelinewidth", 8) 
set (0, "defaultaxeslinewidth", 7) 
plot(1:10, 1:10)
print("-S300,300")
</M>
Page view 012 Octave graphics.png
simple
Edit view
<M output="display" echo>
set (0, "defaultlinelinewidth", 6) 
set (0, "defaultaxeslinewidth", 6) 
plot(1:10, 1:10)
print("-S300,300")
</M>
Page view 012 Octave graphics echo.png

Octave - Mixed output

simple
Edit view
<M>
t = 1:10;
disp(t);
set (0, "defaultlinelinewidth", 5);
set (0, "defaultaxeslinewidth", 5);
plot(t,t);
print(rpdf, "-S300,300");
disp(-t);
plot(t,-t);
print(rpdf, "-S300,300");
</M>
Page view 012 Octave mixed.png
simple with echoing
Edit view
<M echo>
t = 1:10;
disp(t);
set (0, "defaultlinelinewidth", 5);
set (0, "defaultaxeslinewidth", 5);
plot(t,t);
print(rpdf, "-S300,300");
disp(-t);
plot(t,-t);
print(rpdf, "-S300,300");
</M>
Page view 012 Octave mixed echo.png

Octave - Wiki output

simple using outMatrix
Edit view
<M output="wiki">
x = magic(4);
outMatrix(x, 'title', 'magic(4)', 'format.numeric', {'%.0f'});
</M>
Page view 012 Octave wiki outMatrix.png
simple and echoing with using outMatrix
Edit view
<M output="wiki" echo>
x = magic(4);
outMatrix(x, 'title', 'magic(4)', 'format.numeric', {'%.0f'});
</M>
Page view 012 Octave wiki echo outMatrix.png

Octave - Interaction

simple
Edit view
<Rform name="test4">
from: <Rinput name="from" type="text" size="5" value="1" /> 
to: <Rinput name="to" type="text" size="5" value="10" /> 
<Rinput type="submit" value=" Submit " />  
</Rform>

<M  name="test4">
if (exist("from", "var")) 
  from = str2double(from);
else
  from = 1;
end
if (exist("to", "var"))
  to = str2double(to);
else
  to = 10;
end
from:to
</M>
Page view displays a result first, but after pressing the Submit button of the form in a new window will appear with
012 Octave interaction.png
simple using iframe
Edit view
<Rform name="test6">
from: <Rinput name="from" type="text" size="5" value="1" /> 
to: <Rinput name="to" type="text" size="5" value="10" /> 
<Rinput type="submit" value=" Submit " />  
</Rform>

<M  name="test6" iframe>
if (exist("from", "var")) 
  from = str2double(from);
else
  from = 1;
end
if (exist("to", "var"))
  to = str2double(to);
else
  to = 10;
end
from:to
</M>
Page view 012 Octave interaction iframe.png