R Extension for MediaWiki v0.11

Aus sk21
Wechseln zu: Navigation, Suche

Installation

Requirements

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

Tested versions

I do not test the extension/plugin with a lot of systems, here the systems and software versions we have used or tested:

Version Operating system MediaWiki PHP MySQL ImageMagick R Contact
0.02 Suse Linux 9.1 2.0.1
0.02 Suse Linux 10.0 1.5.5 4.4.0 4.1.13 6.2.3 2.1.1 sigbert@wiwi.hu-berlin.de
0.03 Suse Linux 10.0 1.6.5 4.4.0 4.1.13 6.2.3 2.3.0 sigbert@wiwi.hu-berlin.de
0.03 Debian 3.1rev2 1.6.8 4.4.2-0.dotdeb.2 4.0.24_Debian-10sarge2-log 6.0.6 2.1.0 sigbert@wiwi.hu-berlin.de
0.03 Ubuntu 5.10 1.6.6 5.0.5 4.1.12 6.2.3.4 2.1.1 acrida@arrakis.es
0.03 Ubuntu 6.06.1 LTS Server 1.7.1 5.1.2 5.0.22 6.2.4.5 2.3.1 TECason@vcu.edu
0.04 Fedora Core 4 Server 1.8.2 5.0.4 4.1.20 6.2.2 2.4.0 sigbert@wiwi.hu-berlin.de
0.04 Debian 3.1 1.5.8 4.3.10-18 (apache) 4.0.24_Debian-10sarge2-log 6.0.6 2.1.0 baaden@smplinux.de
0.05 Knoppix-based-4.0.2 1.9.3 5.2.1 5.1.16 6.2.0 2.4.1 cchuang@mail.cgu.edu.tw
0.06 Ubuntu 7.10 - LAMP 2.5.1 mario.dicaro@gmail.com
0.06 Ubuntu 6.06 LTS (Lamp) 1.12.0 5.1.2 5.0.22-Debian_0ubuntu6.06.6-log 6.2.4 2.5.1 sigbert@wiwi.hu-berlin.de
0.06 CentOS 5.5 1.6.5 5.2.10 5.0.77 6.2.8 2.12.0 sigbert@wiwi.hu-berlin.de
0.08 Ubuntu 10.04.2 LTS 1.16.2 5.3.2-1ubuntu4.7 5.1.41-3ubuntu12.10 6.5.7-8 2.10.1 sigbert@wiwi.hu-berlin.de
0.08 Debian 6.0 5.3.3-7 5.1.49 6.6.0-4 2.11.1 sigbert@wiwi.hu-berlin.de
0.08_1 Debian 6.0 1.19.0 5.3.3-7 5.1.61-0 6.6.0-4 2.15.0 sigbert@wiwi.hu-berlin.de
0.09_1 Debian 6.0.4 1.20.2 5.3.3-7 5.1.61-0 6.6.0-4 2.15.0 sigbert@wiwi.hu-berlin.de
0.10 Debian 6.0.4 1.20.2 5.3.3-7 5.1.61-0 6.6.0-4 2.15.0 sigbert@wiwi.hu-berlin.de
0.11 Ubuntu 12.10 1.20.2 5.4.6-1ubuntu1.1 5.5.29-0ubuntu0.12.10.1 6.7.7-10 2.15.1 sigbert@wiwi.hu-berlin.de
0.11 Debian 6.0 1.20.2 5.3.3-7+squeeze14 5.1.66-0+squeeze1 6.6.0-4 2.11.1 sigbert@wiwi.hu-berlin.de
0.11_2 Debian 7.1 1.21.1 5.4.4-14+deb7u4 5.5.31-0+wheezy1 6.7.7-10 2.15.1 sigbert@wiwi.hu-berlin.de

If you download the extension and use it successfully on other systems/other software combinations then please let me know such that we can update the list above. Thanks!

Downloading

It is recommend to install the mediawiki from the mediawiki web site and not from package installer of your linux distribution. For a SLES 11 server system an unsolved problem was reported after installing from packages.

After downloading and unpacking

OS-dependent information
OS uid gid Document root
Debian/Ubuntu www-data www-data /var/www
Feodora/CentOS apache apache /var/www/html
Suse Linux wwwrun www /srv/htdocs

After installing the mediawiki, into your Document root/mywiki you should have the following directory and file structure in mywiki (replace mywiki by your wiki name):

drwxr-xr-x 17 root     root       4096 Jan 26 14:35 .
drwxr-xr-x  3 root     root       4096 Jan 25 19:52 ..
-rw-rw-r--  1 root     root       3927 Dez  4 22:07 api.php
-rw-rw-r--  1 root     root        915 Dez  4 22:07 api.php5
drwxrwxr-x  2 root     root       4096 Dez  4 22:07 bin
drwxrwxr-x  2 root     root       4096 Dez  4 22:07 cache
-rw-rw-r--  1 root     root      17878 Dez  4 22:07 COPYING
-rw-rw-r--  1 root     root       3308 Dez  4 22:07 CREDITS
drwxrwxr-x  7 root     root       4096 Dez  4 22:07 docs
drwxrwxr-x 11 root     root       4096 Jan 26 12:16 extensions
-rw-rw-r--  1 root     root         76 Dez  4 22:07 FAQ
-rw-rw-r--  1 root     root        111 Dez  4 22:07 .gitreview
-rw-rw-r--  1 root     root     520791 Dez  4 22:07 HISTORY
drwxrwxr-x  2 www-data www-data   4096 Dez  4 22:07 images
-rw-rw-r--  1 root     root       5915 Dez  4 22:07 img_auth.php
-rw-rw-r--  1 root     root        927 Dez  4 22:07 img_auth.php5
drwxrwxr-x 32 root     root       4096 Dez  4 22:07 includes
-rw-rw-r--  1 root     root       2426 Dez  4 22:07 index.php
-rw-rw-r--  1 root     root        921 Dez  4 22:07 index.php5
-rw-rw-r--  1 root     root       3364 Dez  4 22:07 INSTALL
-rw-rw-r--  1 root     root        774 Dez  4 22:07 .jshintignore
-rw-rw-r--  1 root     root        305 Dez  4 22:07 .jshintrc
drwxrwxr-x  6 root     root       4096 Dez  4 22:07 languages
-rw-rw-r--  1 root     root       1872 Dez  4 22:07 load.php
-rw-rw-r--  1 root     root        919 Dez  4 22:07 load.php5
-rw-r--r--  1 root     root       5172 Jan 26 12:18 LocalSettings.php
drwxrwxr-x 16 root     root      12288 Dez  4 22:07 maintenance
drwxrwxr-x  2 root     root       4096 Jan 25 20:23 Math-master-3044599
drwxrwxr-x  2 root     root       4096 Dez  4 22:07 mw-config
-rw-rw-r--  1 root     root       3853 Dez  4 22:07 opensearch_desc.php
-rw-rw-r--  1 root     root        942 Dez  4 22:07 opensearch_desc.php5
-rw-rw-r--  1 root     root       9453 Dez  4 22:07 profileinfo.php
-rw-rw-r--  1 root     root       4072 Dez  4 22:07 README
-rw-rw-r--  1 root     root       1258 Dez  4 22:07 redirect.php
-rw-rw-r--  1 root     root        927 Dez  4 22:07 redirect.php5
-rw-rw-r--  1 root     root         89 Dez  4 22:07 redirect.phtml
-rw-rw-r--  1 root     root      25066 Dez  4 22:07 RELEASE-NOTES-1.20
drwxrwxr-x 13 root     root       4096 Dez  4 22:07 resources
drwxrwxr-x  2 root     root       4096 Dez  4 22:07 serialized
drwxrwxr-x 12 root     root       4096 Dez  4 22:07 skins
-rw-rw-r--  1 root     root        408 Dez  4 22:07 StartProfiler.sample
drwxrwxr-x  7 root     root       4096 Dez  4 22:07 tests
-rw-rw-r--  1 root     root       1088 Dez  4 22:07 thumb_handler.php
-rw-rw-r--  1 root     root        955 Dez  4 22:07 thumb_handler.php5
-rw-rw-r--  1 root     root      12933 Dez  4 22:07 thumb.php
-rw-rw-r--  1 root     root        940 Dez  4 22:07 thumb.php5
-rw-rw-r--  1 root     root      11575 Dez  4 22:07 UPGRADE
-rw-rw-r--  1 root     root         86 Dez  4 22:07 wiki.phtml

Note that all files belong to the root user except the images directory which belongs to the user under which the webserver runs (see table OS-dependent information above)!

  • The extension/plugin contains the following files which has to be installed in to the mywiki/extensions/R directory:
-rw-r--r--  1 root root   1396 Feb  5 20:38 Convert.php
-rw-r--r--  1 root root  17997 Feb  6 16:26 COPYING
-rw-r--r--  1 root root   2421 Feb  5 20:38 Engine.php
-rw-r--r--  1 root root   2215 Feb  5 20:38 Rcgi.php
-rw-r--r--  1 root root   6763 Feb  5 20:38 REngine.php
-rw-r--r--  1 root root   9077 Feb  3 16:16 Rextension.R
-rw-r--r--  1 root root   2473 Feb  5 20:38 Rform.php
-rw-r--r--  1 root root   5740 Feb  5 20:38 R.php
  • Move the Rcgi.php to the mywiki directory
  • Add in LocalSettings.php the line
require_once('extensions/R/R.php');
  • Create a directory Rfiles in mywiki which is writable for the user under which your webserver (see table OS-dependent information above) runs, e.g. by
mkdir Rfiles
chown -R www-data:www-data Rfiles 

Uploading data

If you want to allow the upload of data files to read them into your R programs with readdataSK then you need add the following line in LocalSettings.php:

$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'csv');

By default Mediawiki will allow to upload a file only if it has one of the first four extensions. If you also want to upload files with other extensions (e.g. csv) you have to add them to the array wgFileExtensions.

Modifying the default settings for R

In extensions/R/R.php you will find an entry of the form

 $engine[] = new REngine('R', 'R');

which defines the computing engine. The first parameter of REngine gives the engine name and the second parameter the command call to R.

Changing the default category for a computing engine

Modify in extensions/R/R.php the following line

 $engine[] = new REngine('R', 'R');

to

 $engine[] = new REngine('R', 'R', 'wikiR');

Running several computing engines parallel

It is possible to use different R versions for computing:

  • Download from http://your_preferred_cran_mirror/src/base/ an R source code package, e.g. R-2.15.2.tar.gz, to your extension directory, e.g. /var/www/mywiki/extensions/R/
  • Unpack the source code package
tar xvfz R-2.15.2.tar.gz
  • Goto to the subdirectory
cd R-2.15.2
  • Configure
./configure --with-x=no --prefix=/var/www/mywiki/extensions/R/R-2.15.2
  • Compile and install
make
make install
  • After sucessful installation the R binary is now at /var/www/mywiki/extensions/R/R-2.15.2/bin/R
  • Add in extensions/R/R.php the entry
$engine[]   = new REngine('R15', '/var/www/mywiki/extensions/R/R-2.15.2/bin/R');

A specific program can be run with the name of the engine, here either R or R15. E.g.

 <R engine="R">R.version</R>

or

 <R engine="R15">R.version</R>

will tell you which engine/R is used. Alternatively you can have a look to the Special page.

Security issues

Level Description Environment
0 no security at all; a R program has to everything access that the www-user has access should only be used in a secure intranet
1 (default) like in R-PHP a bunch of R commands is forbidden could be used in www environment; may still cause problems
2 R programs are executed as a specific user (default: rd) can be securely used in a www environment, an administrator can restrict the user (quotas, rw permissions etc.)

The security levels are nested, everything that does not work in level 1, will not work in level 2 etc.

Activating security level 2

  • Create a user which will be used for executing the R programs, by default I use the name rd, the group of the user has to be the same as the web server user (see table OS-dependent information above)
  • Goto to your mediawiki directory cd .../mywiki
  • Modify the rights of the Rfiles directory and of all files in it in your wiki mywiki by
chmod -R 777 Rfiles
  • Add in the sudoer file (/etc/sudoer for Suse Linux)
wwwrun  mars=(rd) NOPASSWD: ALL 

which allows the user wwwrun to make a sudo to the user rd on host mars without giving a password. Maybe it is a good idea to not give a a shell to the user wwwrun.

  • Edit the file extensions/R.php and add the lines
  $engine['R']           = new REngine('/var/www/mywiki/extensions/R/bin/R');
  $engine['R']->security = 2;
  $engine['R']->sudo     = Engine::getCmd('sudo', '-u rd ');
  • In case that you have not choosen rd then replace rd by myusername.
  • Make sure that sudo is installed

Final security hints

I made the extension as secure as possible. If anybody can imagine further security measures then please let me know. However, some more security steps are highly recommend:

  • Run the Mediawiki and the R programs on a server which is not connected to your intranet.
  • Make regular backups of your server.
  • If you are changing in the R.php the security level to 0 then be aware that every external user can run any R program on your server and has full access to the same files as webuser. This should only be done in a secure intranet.

Documentation

New tags and attributes

<R>...</R>

Runs the R program on save and display its output.

Attribute Values(s) Required
(default)
Meaning
output text
html
display
wiki
no (text) Which kind of output should be taken:
text, html, display for raw output, HTML output and/or PDF graphic(s) from the program (kept for backward compability)
wiki if program generates MediaWiki output
echo none
echo
no (none) Echoing of the R program
none   no echoing
echo   echo the R program input
style #CDATA no style information for the surrounding <pre>...</pre> if generated (meaning of attribute has changed in v0.11)
convert #CDATA no has currently no effect, kept for backward compability
alt #CDATA no has currently no effect, kept for backward compability
onsave -- no Usually the extension/plugin checks if the generated output exists, if yes the R program is not run twice. onsave forces a rerun during saving of a page.
iframe #CDATA no Style information for the <iframe...> with the result of the R program
name #CDATA no name of the <iframe...> element; has to be set if the parameters for the program should come from a form
workspace [A-Za-z0-9_] no name of the workspace which is loaded before the program is run and saved before the end of the program
category [A-Za-z0-9_] no (R) name of the category page to which the current page is added, if the program is saved. An empty name causes no inclusion into a category. The setting of this parameter overwrites the default setting of the computing engine.
engine [A-Za-z0-9_] no (none) name of the computation engine to use. For details see Running different or several computing engines.

<Rform>...</Rform>

Form to enter parameters and run the program

Attribute Values(s) Required
(default)
Meaning
name #CDATA no name of the <iframe...> element to display the result

<Rinput ... />

To define an input element like <input ...> for entering parameters and submit/reset buttons in a <Rform>...</Rform>

Attribute Values(s) Required
(default)
Meaning
type #CDATA yes
(text)
type of input, must be either text, checkbox, radio, submit or reset
name of the text variable in R
name #CDATA partly required if type is either text, checkbox, radio
value #CDATA no specifies the initial value of the control
size #CDATA no specifies initial width of the control. The width is given in pixels except when type attribute has the value text. In that case, its value refers to the (integer) number of characters.
maxlength #CDATA no specifies the maximum number of characters the user may enter. This number may exceed the specified size, in which case the user agent should offer a scrolling mechanism. The default value for this attribute is an unlimited number.
checked no When the type attribute has the value radio or checkbox, it specifies that the button is on
tabindex #CDATA no position in tabbing order
accesskey #CDATA no accessibility key character

<Rarea>...</Rarea>

To define an input element like <textarea>...</textarea> in a <Rform>...</Rform>

Attribute Values(s) Required
(default)
Meaning
name #CDATA yes name of the text variable in R
rows #CDATA no specifies the number of visible text lines
cols #CDATA no specifies the visible width in average character widths
tabindex #CDATA no position in tabbing order
accesskey #CDATA no accessibility key character

Additional R functions and variables

Note that the variables and functions are only available when they are needed, e.g. if output="html" then rpdf is not available.

Variables

Name Meaning
rpdf name of a PDF file which can be used to store a graphics
rhtml has currently no effect, kept for backward compability
rfiles the full path of the Rfiles directory

Function out.HTML

out.HTML creates a HTML table from a matrix or data frame

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)
out.HTML(rhtml, m, title="x\n", format=list(cell="%.4f"))
Parameter Meaning Default value
html set to rhtml, has currently no effect, kept for backward compability
x
Matrix.png
matrix or data frame for the table entries, the colnames and rownames of x will be used as border entries (top and left)
title entry in the upper left cell NULL
caption table caption NULL
style CSS type style information for the table elements as list
style$table for the table
style$caption for the caption
style$col for the column headers background-color:#999999;vertical-align:top;text-align:right;font-weight:bold;
style$row for the row headers background-color:#999999;vertical-align:top;text-align:right;font-weight:bold;
style$title for the title background-color:#999999;vertical-align:top;text-align:right;font-weight:bold;
style$cell matrix for the cells with default values depending on the line number and col vector type:
non-numeric vector and odd line number background-color:#CCCCCC; vertical-align:top; text-align:left;
non-numeric vector and even line number background-color:#FFFFFF; vertical-align:top; text-align:left;
numeric vector and odd line number background-color:#CCCCCC; vertical-align:top; text-align:right;
numeric vector and even line number background-color:#FFFFFF; vertical-align:top; text-align:right;
format sprintf type style information for the table elements as list:
format$cell matrix for the cell formats depends from col vector type
format$col col header formats %s
format$row row header formats %s
format$title title format %s

Function out.Wiki

out.Wiki creates a Mediawiki table from a matrix or data frame

x<-matrix(1:12,ncol=3)
out.Wiki(x, title="x")
Parameter Meaning Default value
x
Matrix.png
matrix or data frame for the table entries, the colnames and rownames of x will be used as border entries (top and left)
title entry in the upper left cell NULL
caption table caption NULL
style CSS type style information for the table elements as list
style$caption for the caption
style$col for the column headers background-color:#999999;vertical-align:top;text-align:right;font-weight:bold;
style$row for the row headers background-color:#999999;vertical-align:top;text-align:right;font-weight:bold;
style$title for the title background-color:#999999;vertical-align:top;text-align:right;font-weight:bold;
style$cell matrix for the cells with default values depending on the line number and col vector type:
non-numeric vector and odd line number background-color:#CCCCCC; vertical-align:top; text-align:left;
non-numeric vector and even line number background-color:#FFFFFF; vertical-align:top; text-align:left;
numeric vector and odd line number background-color:#CCCCCC; vertical-align:top; text-align:right;
numeric vector and even line number background-color:#FFFFFF; vertical-align:top; text-align:right;
format sprintf type style information for the table elements as list:
format$cell matrix for the cell formats depends from col vector type
format$col col header formats %s
format$row row header formats %s
format$title title format %s

Function outHTML

outHTML creates a HTML table from a matrix (deprecated, use out.HTML instead)

Parameter Meaning Default value
html set to rhtml, has currently no effect, kept for backward compability
x
Matrix.png
matrix for the table entries, the colnames and rownames of the matrix will be used as border entries (top and left)
title entry in the upper left cell ""
style CSS type style information for the table width:100%;
tstyle CSS type style information for the upper left cell background-color:#BBBBBB; vertical-align:top; text-align:left;
cstyle CSS type style information for the column headers background-color:#BBBBBB; vertical-align:top; text-align:right;
rstyle CSS type style information for the row headers background-color:#BBBBBB; vertical-align:top; text-align:right;
ostyle CSS type style information for the odd rows background-color:#FFFFFF; vertical-align:top; text-align:left;
estyle CSS type style information for the even rows background-color:#CCCCCC; vertical-align:top; text-align:left;
... further parameters which are used for the formatC routine to format

Function trellisSK

trellis.device can be used, but the use of file=... is not allowed. Therefore we defined our own function which takes as first parameter the filename. So use trellisSK instead of trellis.device.

Parameter Meaning Default value
file in file is the graphic stored
... further named parameters given to trellis.device

Function readdataSK

readdataSK reads uploaded data into R. It uses internally the functions read.table, read.csv and read.csv2. The filename must be unique otherwise readdataSK will throw a R error.

Parameter Meaning Default value
name name of the file with extension
format one of the format strings

csv   (default) for english Excel files using read.csv
csv2  for german Excel files using read.csv2
table for raw ascii data using read.table
txt   if name contains the ascii data using read.table in connection with textConnection

... further named parameters given to read.XXX commands

Function pdf

pdf overwrites the function graphics::pdf. Since an output can contain several graphics the variable rpdf (name of the graphic file) contains a placeholder for the index. Additionally the file parameter is captured.

Parameter Meaning Default value
name the parameter is ignored
... all other parameters are passed to graphics::pdf

Function dev.off

dev.off overwrites the function grDevices::dev.off. A graphics started with pdf will be placed in the output after the dev.off call. The index for the graphic file is increased by one.

Parameter Meaning Default value
which shuts down the specified (by default the current) device dev.cur()

Special page

The extension creates also a special page under Special:R. It gives as a list the following information about the available computing engines:

Name of engine
Engine version
Category used

If in mywiki/extension/R.php is set (default)

 $wgRSpecialFull = true;

then a lot of additional information is given.

Contents of the files

Here are short overview what the files installed in the Mediawiki are good for.

File Usage
Rcgi.php Script called when you use an interactive example.
extensions/R/R.php The main file: Set up and handling of the <R> tag.
extensions/R/R.i18n.php The internationalisation file.
extensions/R/Rextension.R The R program that contains outHTML, out.HTML, out.Wiki, trellisSK, readdataSK.
extensions/R/COPYING Licence information.
extensions/R/Convert.php Contains the class Convert to convert graphics, e.g. pdf to png or jpg. Supports currently only ImageMagick.
extensions/R/Engine.php Contains the abstract class Engine to run a statistical software engine for computing.
extensions/R/REngine.php Contains the class REngine to run the statistical software R.
extensions/R/renderRform.php Handles the <Rform>, <Rinput> and <Rarea> tags.
extensions/R/SpecialR.php Generate the wiki page Special:R.

Error messages

Errors which appear instead of the expected R output can fall in two categories

User errors
These kind of errors are most likely caused by your R program code or wrong parameters to the tags. You should be able to correct these errors yourself.
Sysop errors
These kind of errors are most likely caused during the extension installation. To correct these error you need access to the server where the wiki is located. This means only a server administrator will able to do so.

User errors

REngine.php: ...
Your R program produced some error. ... is the output from the R program which may help you to diagnose what happened
Engine.php: Engine "..." not found
The computing engine is not found. Check your spelling and compare with Version page
Eingine.php: You can not use wiki output in a iframe
If use output="wiki" then it can not be written into an iframe
Engine.php: security check failed: used banned command or parameter "..."
Some commands of the computing engine are forbidden. Correct your R program.
Engine.php: security check failed, found <php ...
The output from your program contains PHP code
Engine.php: security check failed, found <script ...
The output from your program contains JavaScript code
Engine.php: iframe attribute required in corresponding <R...> tag
You must use the iframe attribute with interactive programs
Rform.php: Rinput attribute "type" can be only "text", "checkbox", "radio", "submit" or "reset"'
You have an <Rinput ... > with wrong attribute(s). Check what you typed

Sysop errors

Convert.php: Either graphic input or output is not supported: ... -> ...
The Convert object does not know how to convert a graphics from ... to ... Check if the graphic extensions are correctly written.
Convert.php: Can not convert "..."
The Convert object does not know how to convert a graphics from ... to ... Check if the graphic extensions are correctly written and the graphic file generated from the engine has the correct extension.
Convert.php: File "..." does not exist
The conversion has failed and the destination file has not been created. In case of R you may check if the pdf file contains several pages (not supported by the extension)
Convert.php: ...
Some error has occured in converting a graphic. ... is the output from the conversion program which may help you to diagnose what happened
Engine.php: you will hopefully never see this!
Something really strange has happened. Check the function Engine::formatOutput.
Engine.php: file "..." not found
The program parameter file of an interactive program could not be found
Engine.php: $params["sha1"] not found
The name of the target iframe is missing
Engine.php: $params["engine"] not found
The name of the computing engine is missing

Frequently asked questions

Installation

Q: After installing the extension just a blank page is shown if I try to access my mediawiki.

A: Have a look to your web servers log file. If some program is missing, e.g. R, convert or sudo then an exception is thrown which appears in the logfile and produces blank pages.

Q: My R programs worked perfectly when my base address was http://www.myaddress.de/mediawiki/xyz. Now I have made my own domain http://www.myXYZdomain.de which is my new base adress and the R programs do not work anymore. What I can do ?

Shoud not happen anymore since the extension uses now wgServer and wgScriptPath.

Graphics

Q: Internet Explorer displays instead of the generated graphics just a red cross, but in XXX browser the graphics is shown. What happened?

A: The extension generates JPG graphics (default is now PNG). However, the default for ImageMagick is to generate graphics in CYMK colorspace which IE just display with a red cross (to check go to [1]). Either ask the owner of the wiki to update the extension (at least version 0.10), to change to PNG graphics or you have to use another browser.

Using data files

Q: I uploaded an Excel CSV file, but it complains "more columns than column names".

A: If you have a german Excel CSV file then use readdataSK("myname.csv", format="csv2").

Q: I try to read in a file, but it complains "invalid 'description' argument".

A: Check if the file is uploaded under the given name. Mediawiki capitalizes usually the first letter of the file name and this matters on UNIX machines.

Link to category page

Q: I updated the R extension version, but the Category page Category:R is empty. Why do the pages with R programs do not appear?

A: You need to force that the pages with a program are rebuild from the wiki source.

#!/usr/bin/perl -w
use MediaWiki::DumpFile;

 my $file  = shift(@ARGV) or die "must specify a Mediawiki dump file";
 my $mw    = MediaWiki::DumpFile->new;
 my $pages = $mw->fastpages($file);
 while(($title, $text) = $pages->next) {
     if (index($text, '/R') != -1) {
       print $title, "\n";
     }
 }

Q: I do not like the Category:R entry at the end of the wiki page. How can I avoid it?

A: There exists three possibilities:

  1. You can use in your program call(s) the category attribute:
 <R category="">1:10</R>
  1. You can hide the category, see Hidden_categories in the MediaWiki wiki. The category still exists and can be used further, but will be not shown on the wiki pages.
  2. You can reset the default category in R.php for an engine, see Changing the default category for a computing engine.

Security issues

Q: If the security level is set to one or higher which R command can not be used ?

A: I have taken the list of commands from R-PHP people as basis.

Command Description
.C The functions '.C' and '.Fortran' can be used to make calls to C and Fortran code.
.Call '.Call' and '.Call.graphics' can be used call compiled code which makes use of internal R objects.
.Call.graphics '.Call' and '.Call.graphics' can be used call compiled code which makes use of internal R objects.
.External '.External' and '.External.graphics' can be used to call compiled code that uses R objects in the same way as internal R functions.
.External.graphics '.External' and '.External.graphics' can be used to call compiled code that uses R objects in the same way as internal R functions.
.Fortran The functions '.C' and '.Fortran' can be used to make calls to C and Fortran code.
.readRDS A simple low level interface for serializing to connections.
.saveRDS A simple low level interface for serializing to connections.
.Script Run a script through its interpreter with given arguments.
.Tcl Low-level Tcl/Tk Interface.
.Tcl.args Low-level Tcl/Tk Interface.
.Tcl.callback Low-level Tcl/Tk Interface.
.Tk.ID Low-level Tcl/Tk Interface.
.Tk.newwin Low-level Tcl/Tk Interface.
.Tk.subwin Low-level Tcl/Tk Interface.
.Tkroot Low-level Tcl/Tk Interface.
.Tkwin Low-level Tcl/Tk Interface.
basename 'basename' removes all of the path up to the last path separator (if any).
browseURL Load a given URL into a WWW browser.
bzfile Function to create, open and close connections.
call Create objects of mode "call"
capture.output Evaluates its arguments with the output being returned as a character string or sent to a file. Related to 'sink' in the same way that 'with' is related to 'attach'.
close 'close' closes and destroys a connection.
close.screen 'close.screen' removes the specified screen definition(s).
closeAllConnection 'closeAllConnections' closes (and destroys) all open user connections, restoring all 'sink' diversions as it does so.
data.entry A spreadsheet-like editor for entering or editing data.
data.restore Reads binary data files or 'data.dump' files that were produced in S version 3.
dataentry A spreadsheet-like editor for entering or editing data.
de A spreadsheet-like editor for entering or editing data.
dev.control 'dev.control' allows the user to control the recording of graphics operations in a device.
dev.copy2eps 'dev.copy2eps' is similar to 'dev.print' but produces an EPSF output file, in portrait orientation ('horizontal = FALSE').
dev.cur This function provides control over multiple graphics devices.
dev.list This function provides control over multiple graphics devices.
dev.next This function provides control over multiple graphics devices.
dev.prev This function provides control over multiple graphics devices.
dev.print This function provides control over multiple graphics devices.
dev.set This function provides control over multiple graphics devices.
dev2bitmap 'dev2bitmap' copies the current graphics device to a file in a graphics format.
dget Writes an ASCII text representation of an R object to a file or connection, or uses one to recreate the object.
dir This function produces a list containing the names of files in the named directory.
dir.create 'dir.create' creates a directory.
dirname "'dirname' returns the part of the 'path' up to (but excluding) the last path separator, or '"".""' if there is no path separator."
do.call 'do.call' executes a function call from the name of the function and a list of arguments to be passed to it.
download.file This function can be used to download a file from the Internet.
dput Writes an ASCII text representation of an R object to a file or connection, or uses one to recreate the object.
dump This function takes a vector of names of R objects and produces text representations of the objects on a file or connection.
dyn.load Load or unload shared libraries, and test whether a C function or Fortran subroutine is available.
edit Invoke a text editor on an R object.
edit.data.frame Use data editor on data frame or matrix contents.
emacs Invoke a text editor (emacs) on an R object.
erase.screen 'erase.screen' is used to clear a single screen, which it does by filling with the background colour.
eval Evaluate an R expression in a specified environment.
example Run all the R code from the *Examples* part of R's online help topic 'topic' with two possible exceptions, 'dontrun' and 'dontshow', see Details below.
fifo Function to create, open and close connections.
file Function to create, open and close connections.
file.access Utility function to access information about files on the user's file systems.
file.append 'file.append' attempts to append the files named by its second argument to those named by its first. The R subscript recycling rule is used to align names given in vectors of different lengths.
file.choose Choose a file interactively.
file.copy 'file.copy' works in a similar way to 'file.append' but with the arguments in the natural order for copying.
file.create 'file.create' creates files with the given names if they do not already exist and truncates them if they do.
file.exists 'file.exists' returns a logical vector indicating whether the files named by its argument exist.
file.info Utility function to extract information about files on the user's file systems.
file.path Construct the path to a file from components in a platform-independent way.
file.remove 'file.remove' attempts to remove the files named in its argument.
file.rename 'file.rename' attempts to rename a single file.
file.show Display one or more files.
file.symlink 'file.symlink' makes symbolic links on those Unix-like platforms which support them.
fix 'fix' invokes 'edit' on 'x' and then assigns the new (edited) version of 'x' in the user's workspace.
getConnection 'getConnection' returns a connection object, or 'NULL'.
getwd "'getwd' returns an absolute filename representing the current working directory of the R process; 'setwd(dir)' is used to set the working directory to 'dir'."
graphics.off 'graphics.off()' shuts down all open graphics devices.
gzcon 'gzcon' provides a modified connection that wraps an existing connection, and decompresses reads or compresses writes through that connection.
gzfile 'gzfile' applies to files compressed by 'gzip', and 'bzfile' to those compressed by 'bzip2': such connections can only be binary.
INSTALL Utility for installing add-on packages.
install.packages Download Packages from CRAN.
jpeg A graphics device for JPEG format bitmap files.
library.dynam Load the specified file of compiled code if it has not been loaded already, or unloads it.
list.files This function produces a list containing the names of files in the named directory. 'dir' is an alias.
loadhistory Load the commands history.
locator Reads the position of the graphics cursor when the (first) mouse button is pressed.
lookup.xport Lookup information on a SAS XPORT format library
make.packages.html Functions to re-create the HTML documentation files to reflect all installed packages.
make.socket Create a Socket Connection.
menu 'menu' presents the user with a menu of choices labelled from 1 to the number of choices.
open 'open' opens a connection.
parent.frame Function to Access the Function Call Stack.
path.expand Expand a path name, for example by replacing a leading tilde by the user's home directory (if defined on that platform).
pico Invoke a text editor (pico) on an R object.
pictex This function produces graphics suitable for inclusion in TeX and LaTeX documents.
pipe Function to create, open and close connections.
png A graphics device for PNG format bitmap files.
postscript 'postscript' starts the graphics device driver for producing PostScript graphics.
print.socket Related to 'make.socket'.
prompt Facilitate the constructing of files documenting R objects.
promptData Generates a shell of documentation for a data set.
quartz 'quartz' starts a graphics device driver for the MacOS X System. This can only be done on machines that run MacOS X.
R.home Return the R home directory.
R.version 'R.Version()' provides detailed information about the version of R running.
read.00Index Read 00Index-style Files.
read.dta Read Stata binary files.
read.epiinfo Read Epi Info data files
read.fwf "Read a ""table"" of *f*ixed *w*idth *f*ormatted data into a 'data.frame'."
read.mtp Read a Minitab Portable Worksheet.
read.socket 'read.socket' reads a string from the specified socket.
read.spss Read an SPSS data file.
read.ssd Obtain a data frame from a SAS permanent dataset.
read.xport Read a SAS XPORT format library.
readBin Read binary data from a connection.
readdataSK Read data from files (only banned when security=2).
readline 'readline' reads a line from the terminal.
readLines Read text lines from a connection.
remove.packages Removes installed packages and updates index information as necessary.
Rprof Enable or disable profiling of the execution of R expressions.
save 'save' writes an external representation of R objects to the specified file.
savehistory Save the commands history.
scan Read data into a vector or list from the console or file.
screen 'screen' is used to select which screen to draw in.
seek Functions to re-position connections.
setwd 'getwd' returns an absolute filename representing the current working directory of the R process.
showConnection 'showConnections' returns a character matrix of information with a row for each connection, by default only for open non-standard connections.
sink 'sink' diverts R output to a connection.
sink.number 'sink.number()' reports how many diversions are in use.
socketConnection Function to create, open and close connections.
source Read R Code from a File or a Connection.
split.screen 'split.screen' defines a number of regions within the current device which can, to some extent, be treated as separate graphics devices.
stderr 'stdin()', 'stdout()' and 'stderr()' return connection objects.
stdin 'stdin()', 'stdout()' and 'stderr()' return connection objects.
stdout 'stdin()', 'stdout()' and 'stderr()' return connection objects.
sys.call Function to Access the Function Call Stack.
sys.calls Function to Access the Function Call Stack.
sys.frame Function to Access the Function Call Stack.
sys.frames Function to Access the Function Call Stack.
sys.function Function to Access the Function Call Stack.
Sys.getenv 'Sys.getenv' obtains the values of the environment variables named by 'x'.
Sys.getlocale Get details of or set aspects of the locale for the R process.
Sys.info Reports system and user information.
sys.nframe Function to Access the Function Call Stack.
sys.on.exit Function to Access the Function Call Stack.
sys.parent Function to Access the Function Call Stack.
sys.parents Function to Access the Function Call Stack.
Sys.putenv 'putenv' sets environment variables (for other processes called from within R or future calls to 'Sys.getenv' from this R process).
Sys.sleep Suspend execution of R expressions for a given number of seconds.
Sys.source Parse and Evaluate Expressions from a File.
sys.source Parse and Evaluate Expressions from a File.
sys.status Function to Access the Function Call Stack.
Sys.time 'Sys.time' and 'Sys.Date' returns the system's idea of the current date with and without time.
system 'system' invokes the OS command specified by 'command'.
system.file Finds the full file names of files in packages etc.
tempfile 'tempfile' returns a vector of character strings which can be used as names for temporary files.
textConnection Input and output text connections.
tkpager Page file using Tk text widget.
tkStartGUI Tcl/Tk GUI startup.
unlink 'unlink' deletes the file(s) or directories specified by 'x'.
unz 'unz' reads (only) single files within zip files, in binary mode.
update.packages Download Packages from CRAN.
url Function to create, open and close connections.
url.show Display a text URL.
vi Invoke a text editor (vi) on an R object.
write Write Data to a File.
write.dta Write files in Stata binary format.
write.ftable Manipulate Flat Contingency Tables.
write.socket 'write.socket' writes to the specified socket.
write.table 'write.table' prints its required argument 'x' (after converting it to a data frame if it is not one already) to 'file'.
writeBin Write binary data to a connection.
writeLines Write Lines to a Connection.
x11 'X11' starts a graphics device driver for the X Window System (version 11).
X11 'X11' starts a graphics device driver for the X Window System (version 11).
xedit Invoke a text editor on an R object.
xemacs Invoke a text editor on an R object.
xfig 'xfig' starts the graphics device driver for producing XFig (version 3.2) graphics.
zip.file.extract This will extract the file named 'file' from the zip archive, if possible, and write it in a temporary location.

Examples

Raw simple with echoing with echoing and in iframe
Edit view
<R>1:10</R>
<R echo>1:10</R>
<R iframe="width:100%;height:50px" echo>1:10</R>
Page view RExample1.png RExample8.png RExample9.png
HTML simple with echoing with echoing and in iframe
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)
outHTML(rhtml, m, title="x\n", format="f", digits=4)
</R>
<R output="html" 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)
outHTML(rhtml, m, title="x\n", format="f", digits=4)
</R>
<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)
outHTML(rhtml, m, title="x\n", format="f", digits=4)
</R>
Page view RExample10.png RExample11.png RExample12.png
Graphics simple with echoing with echoing and in iframe
Edit view
<R output="display">
pdf(rpdf, width=3, height=3)
plot(1:10, 1:10)
</R>
<R output="display" echo>
pdf(rpdf, width=3, height=3)
plot(1:10, 1:10)
</R>
<R  output="display" iframe="height:250px" echo>
pdf(rpdf, width=3, height=3)
plot(1:10, 1:10)
</R>
Page view RExample13.png RExample14.png RExample15.png
Mixed simple with echoing with echoing and in iframe
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>
<R echo>
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>
<R iframe="height:600px" echo> 
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 RExample17.png RExample18.png
Wiki simple with echoing with echoing and in iframe
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)
out.Wiki(x, title="x")
</R>
<R output="wiki" echo>
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>
<R output="wiki" iframe="height:100px" echo>
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>
Page view RExample19.png RExample20.png RExample20.png
Interaction simple with echoing in a iframe
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>
<Rform name="test2">
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="test2" echo>
if (exists("from")) from <- as.numeric(from) else from <- 1
if (exists("to")) to <- as.numeric(to) else to <- 10
from:to 
</R>
<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 After pressing Submit the browser writes into the (new) window
RExample21.png
After pressing Submit you'll get
RExample22.png