R-tools

From Testiwiki
Revision as of 10:54, 27 June 2011 by Ehac (talk | contribs)
Jump to: navigation, search



R-Tools is a MediaWiki extension that allows registered Opasnet users to run R code directly from a wiki page.

Question

How should R-based modelling be performed in a MediaWiki environment?

Answer

Libraries

Opasnet R software has some additional libraries installed for plotting (e.g. ggplot2) and also some libraries that enable connecting to external databases (e.g. OpasnetBaseUtils). More libraries can be installed on request with proper reasons.

Usage

R-tools uses <rcode> tags. Any R code written between these tags can be run from wiki page using the "Run code"-button. Press the button and new window (or tab) opens up showing the status and the results of the run in real time. An example code that counts one plus one using R:

<rcode>
1+1
</rcode>

Parameters

Some optional parameters can be given to <rcode> tag as described below.

  • graphics - If the code is meant to draw any graphs then define graphics to '1'.
  • variables - Allows user to input values for named variables in R code. Inputs will be displayed in a box below the actual R code in wiki page. Variables syntax is described in its own chapter on this page.

Variables syntax (legacy way)

Each variable needs three attributes separated with | (pipe) character. These attributes (in correct order) are variable name in code,variable description in wiki page and default value. Variable triplets must also be separated with pipe. An example R code with two defined attributes calculates the area of a rectangle:

<rcode variables="width|Width of the rect|10|height|Height of the rect|10">
# The area of the rect is
width *  height
</rcode>

Note that variable default value can also be a string or even an array (e.g. c(1,2,3) or 'Some name').

Variables syntax (new way with more possibilities)

Each variable can have a set of attributes. Attributes must be given as name/value pairs, separated with colon (:). Each variable must have at least one attribute, which is called "name" (variable name in R code). Optionally "description" attribute can be defined to give users more information about the variable. All variables are considered as text type by default, providing users a input field for writing. There are other possible types too (date, select, checkbox...) and the list of possibilities may grow longer in future. Variable type can be defined by giving it "type" attribute. Different types for variables are described in their own chapter on this page. Each attribute must be separated with vertical bar (aka pipe) character. Example code with two variables defined:

<rcode variables="name:width|name:height|description:Rect height">
# The area of the rect is
width *  height
</rcode>

Variable types

This chapter describes all the implemented variable types.

text

This is the default type if "type" attribute is not present. Renders a text field where users can input any text. Given input will be assigned to R variable as is, making it possible to use this type for inputting strings, numbers, vectors etc. Optionally "default" attribute can be given to insert predefined value to text field.

date

Renders three select-elements for choosing a day, month and year. Given date will be assigned to R variable as date (as.Date).

select

checkbox

Rationale

See also

Keywords

References


Related files

<mfanonymousfilelist></mfanonymousfilelist>