Open main menu
MediaWiki extensions manual
OOjs UI icon advanced.svg
R
Release status: unmaintained
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.26.0
Database changes No
License GNU General Public License 3.0 or later
Download

  • <R>
  • <M>
  • <Rform>
  • <Rinput>
  • <Rarea>
Translate the R extension if it is available at translatewiki.net
Check usage and version matrix.
Warning Warning: This extension will not work with PHP 7.0.0 or higher!

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.

RequirementsEdit

  • 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.

DownloadEdit

You can obtain the extension at this offsite location.

InstallationEdit

The installation instruction are for version 0.14 of the extension. For earlier versions, please consult documentation for your version of the extension.
  1. Go to the extensions directory and
    1. either extract the downloaded files
    2. or clone it from GitHub
      git clone https://github.com/sigbertklinke/R
      
  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.

ExamplesEdit

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.

UsageEdit

Example Page (edit mode) Page (view mode)
Raw output
<R>1:11</R>
 
Raw iframe output
 <R iframe="width:100%;height:40px">1:10</R>
 
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>
 
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>
 
Graphics
 
 <R output="display">
 pdf(rpdf)
 plot(1:10, 1:10)
 </R>
 
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>
 
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>
 

See alsoEdit