Difference between revisions of "R and Calc Documentation"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
Line 23: Line 23:
  
 
<code>RNMAT("library(sna);gden"; A1:D4)</code>
 
<code>RNMAT("library(sna);gden"; A1:D4)</code>
 +
 +
==Creating Your Own Dialogs and Scripts==
 +
 +
Using a basic text file, it is possible to create your own scripts and functions that will then call R and provide output. A basic [http://www.11-55.org/ooblog/wp-content/uploads/2007/05/correl-may-21.txt correlation example] is provided, and an outline of the tile structure is given below.
 +
 +
First and foremost, there are four sections to a file:
 +
* '''__ETC:''' ignored -- a set of comments.
 +
* '''__GUI:''' for user interface objects.
 +
* '''__CALL:''' allows you to define the R function call based on GUI inputs.
 +
* '''__OUTPUT:''' allows you to set where the output will go.
 +
 +
===Using __GUI:===
 +
 +
Currently, the following GUI objects can be defined in the file:
 +
* '''TextField:''' for text-based arguments.
 +
* '''NumberField:''' for numeric arguments, but not references to the spreadsheet.
 +
* '''ArrayField:''' refers to data in the spreadsheet (current active sheet).
 +
* '''Label:''' a basic label.
 +
* '''RunButton:''' runs the code and prints output.
 +
* '''CancelButton:''' closes the dialog.
 +
* '''Dialog:''' allows you to define the size and location of the dialog.
 +
 +
The format for the above is as follows, with ''italic'' fields representing variables and parameters: ''Object_Name''<-Label( ''x position'' , '' y position '', ''width'' , ''height'', ''label_text'' ).
 +
 +
===Using __CALL:===
 +
 +
In this case, simply write your call text, with variables being represented as {$''variable-name''} where the name itself corresponds to the names you gave the GUI objects above. This only works with TextField, NumberField, and ArrayField.
 +
 +
===Using __OUTPUT:===
 +
 +
In this case, you write every line like so: ''Cell-Address''<-''Value'' where ''Value'' is either the name of a specific property in the R object structure (e.g. ''p.value'' or ''estimate'') or a general piece of text. The software will always test to see if your text is a property, and if it is not, the text itself will be printed.
  
 
[[Category:Calc]]
 
[[Category:Calc]]

Revision as of 22:39, 23 May 2007

Please note that this documentation is not for Version 0.1.0, but rather for an upcoming release. See the main R and Calc page for current documentation.

Cell Functions

Note that the function names may change in future versions... I'm not really concerned about properly naming everything for users yet, but making things simpler for development.

  • RNDBLMAT( <command> , <matrix> , <matrix>): passes a command and two matrices. For example, RNDBLMAT("cov";A1:A100;B1:B100).
  • RNMAT( <command> , <matrix> ): passes a command and matrix as a parameter. For example, RNNUM("var";A1:A100).
  • RNNUM( <command> , <number> ): passes a command and a numeric parameter. For example, RNNUM("rnorm"; 1).
  • RNUMPROP( <command> , <property> ): passes a command to R and prints a specific property from the output. This is useful if the values returned from R aren't numeric but contain a variety of information. For example, RNUMPROP("cor.test(c(1,2,3,4), c(1,2,2,3))"; "p.value").
  • RSIMPLENUM( <command> ): passes a command to R, prints a number if one is returned.
  • RTESTCONNECTION(): tests R connection (for RServe).

R Add-On Menu

  • RDUMP(): creates a new spreadsheet with the object structure returned by a specific R script.

Tips & Tricks

Running External Libraries

At this time, it's not possible to load libraries ahead of time using Rserve. However, you can load a library through a function cell. The example below loads a library called sna and calls a function, passing a matrix as a parameter. Note that the library needs to be installed prior to using it.

RNMAT("library(sna);gden"; A1:D4)

Creating Your Own Dialogs and Scripts

Using a basic text file, it is possible to create your own scripts and functions that will then call R and provide output. A basic correlation example is provided, and an outline of the tile structure is given below.

First and foremost, there are four sections to a file:

  • __ETC: ignored -- a set of comments.
  • __GUI: for user interface objects.
  • __CALL: allows you to define the R function call based on GUI inputs.
  • __OUTPUT: allows you to set where the output will go.

Using __GUI:

Currently, the following GUI objects can be defined in the file:

  • TextField: for text-based arguments.
  • NumberField: for numeric arguments, but not references to the spreadsheet.
  • ArrayField: refers to data in the spreadsheet (current active sheet).
  • Label: a basic label.
  • RunButton: runs the code and prints output.
  • CancelButton: closes the dialog.
  • Dialog: allows you to define the size and location of the dialog.

The format for the above is as follows, with italic fields representing variables and parameters: Object_Name<-Label( x position , y position , width , height, label_text ).

Using __CALL:

In this case, simply write your call text, with variables being represented as {$variable-name} where the name itself corresponds to the names you gave the GUI objects above. This only works with TextField, NumberField, and ArrayField.

Using __OUTPUT:

In this case, you write every line like so: Cell-Address<-Value where Value is either the name of a specific property in the R object structure (e.g. p.value or estimate) or a general piece of text. The software will always test to see if your text is a property, and if it is not, the text itself will be printed.

Personal tools