Extension:R

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

Release status: beta

Implementation Tag, Special page
Description Allows to integrate R and Octave output (raw, html and graphics) on pages
Author(s) Sigbert Klinke (Sigberttalk)
Latest version 0.14_1 (2014-08-22)
MediaWiki 1.5.5 - 1.23.2
Database changes No
License GNU General Public License
Download offsite location
Tags
  • <R>
  • <M>
  • <Rform>
  • <Rinput>
  • <Rarea>
Hooks used
ParserFirstCallInit

Translate the R extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

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

Requirements[edit | edit source]

  • 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.
  • Optional: GNU Octave is a high-level interpreted language, primarily intended for numerical computations. It needs to be installed (probably available in your Linux distribution) and in the PATH: the command octave should work on the command line.
  • ImageMagick is a software suite to create, edit, compose, or convert bitmap images. It needs 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 | edit source]

You can obtain the extension at this offsite location.

Installation[edit | edit source]

The installation instruction are for version 0.14 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. Create a directory Rfiles in the root directory of your wiki
    mkdir Rfiles
    
  4. Make it writable for the web server user (for Debian or Ubuntu www-data:www-data)
    chown -R www-data:www-data Rfiles
    
  5. Initial installation can now be verified through Special:Version of your wiki.
  6. Further information can be found under Special:R page of your wiki.

Examples[edit | edit source]

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. For examples of the current version see the example page at the offsite location.

Usage[edit | edit source]

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 | edit source]

See also[edit | edit source]