Extension:R

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
R

Release status: beta

Implementation Tag, Special page
Description Allows to integrate R output (raw, html and graphics) on pages
Author(s) Sigbert Klinke (Sigberttalk)
Last version 0.11 (13 February 2013)
MediaWiki 1.5.5 - 1.20.2
Database changes no
License GPL
Download offsite location
Tags
  • <R>
  • <Rform>
  • <Rinput>
  • <Rarea>
Hooks used
ParserFirstCallInit
Check usage and version matrix; stats

The R extension allows to integrate output (raw text, HTML and graphics) from R programs, which is is a free software environment for statistical computing and graphics, on pages.

Contents

Requirements[edit]

  • R is a free software environment for statistical computing and graphics. It needs to be installed (probably available in your Linux distribution) and in the PATH: the command R should work on the command line.
  • ImageMagick is a software suite to create, edit, compose, or convert bitmap images. It need to be installed (probably available in your Linux distribution) and in the PATH: the command convert should work on the command line. If you enabled TeX then it should have been installed already.

Download[edit]

You can obtain the extension at this offsite location.

Installation[edit]

The installation instruction are for version 0.11 of the extension. For earlier versions, please consult documentation for your version of the extension.
  1. Extract the downloaded files into your extensions directory.
  2. Add
    require_once( "$IP/extensions/R/R.php" );
    to the bottom of LocalSettings.php.
  3. Copy Rcgi.php to the root directory of your wiki
    cp extensions/R/Rcgi.php .
    
  4. Initial installation can now be verified through Special:Version of your wiki.
  5. Further information can be found under Special:R page of your wiki.

Examples[edit]

All examples are done with version v0.10 of the extension. They may not work with other versions, please consult documentation for your version of the extension.

Usage[edit]

Example Page (edit mode) Page (view mode)
Raw output
<R>1:10</R>
RExtensionExample1.png
Raw iframe output
<R iframe="width:100%;height:40px">1:10</R>
RExtensionExample2.png
HTML output
<R output="html" iframe="width:100%;height:250px;">
prob=0.15; nmin=1; nmax=15; x=6
m <-pbinom(rep(0:x, each = 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)
outHTML(rhtml, m, title="x\n", format="f", digits=4)
</R>
RExtensionExample4.png
Wiki output
<R output="wiki">
x<-matrix(1:12,ncol=3)
rownames(x) <- sprintf("row %i", 1:4)
colnames(x) <- sprintf("col %i", 1:3)
out.Wiki(x, title="x")
</R>
RExtensionExample7.png
Graphics
<R output="display">
pdf(rpdf)
plot(1:10, 1:10)
</R>
RExtensionExample3.png
Complex graphics
<R output="display" iframe="width:400px;height:400px">
pdf(rpdf, width=5, height=5)
n    <- 10
prob <- 0.2
x <- seq(0, n, 1)
p <- dbinom(x, n, prob)
param <- list(n, prob)
main <- c("Binomialverteilung - Wahrscheinlichkeitsfunktion", 
  paste (c("Stichprobenumfang n", "Wahrscheinlichkeit p"), param, sep="="))
plot(x,p, type="h", main=main)
</R>
RExtensionExample5.png
Interaction
<Rform name="binom">
n: <Rinput name="n" type="text" size="5" maxlength="5" value="10" /> 
prob: <Rinput name="prob" type="text" size="5" maxlength="5" value="0.2" /> 
<Rinput type="submit" value=" Submit " /> 
</Rform>
<R output="display" name="binom" iframe="height:400px;">
if (exists("prob")) prob <- as.numeric(prob) else prob <- 0.2
if (exists("n")) n <- as.numeric(n) else n <- 10
x <- seq(0, n, 1)
p <- dbinom(x, n, prob)
param <- list(n, prob)
main <- c("Binomialverteilung - Wahrscheinlichkeitsfunktion", 
  paste (c("Stichprobenumfang n", "Wahrscheinlichkeit p"), param, sep="="))
pdf(pdf, width=5, height=5)
plot(x,p, type="h", main=main)
</R>
RExtensionExample6.png

Wikis[edit]

See also[edit]