LiveCompare includes a number of sample R scripts
that perform common workflow tasks, or provide useful examples. These
scripts are stored in text files with a .r extension, and are installed
to the <LiveCompare user data dir>\private\RScripts directory as part of
the LiveCompare Standard Apps
package. To use a script from the repository, set the Execute
R action’s Script property to the name of the script file by selecting
an entry from the property's drop-down list. If the Script property is
set, any Statements specified for the Execute R action will not be executed.
The following R script files are included.
CopyTable1DataToResultTable.r
Copies the Table1 source table to a result
table named ResultTable. The metadata for Table1 is not copied.
CopyTable1MetadataToResultTable.r
Copies the column types, column lengths and
column keys from the Table1 source table to an existing table named ResultTable.
This script should be run from the Execute R action’s Statements parameter,
as described below.
CopyTable2DataToResultTable.r
Copies the Table2 source table to a result
table named ResultTable. The metadata for Table2 is not copied.
CopyTable2MetadataToResultTable.r
Copies the column types, column lengths and
column keys from the Table2 source table to an existing table named ResultTable.
This script should be run from the Execute R action’s Statements parameter,
as described below.
RemovePrefixesFromResultTable.r
Removes the <Table Name>_ prefixes from
columns in the ResultTable table. This script should be run from the Execute
R action’s Statements parameter, as described below.
TableAddTotalCol.r
Adds a column named TOTALS to the ResultTable
table and populates it with totals for each numeric row. Copies the metadata
from the Table1 table to the ResultTable table.
TableAddTotalColRow.r
Adds a column named TOTALS to the ResultTable
table and populates it with totals for each numeric row value. Adds a
row named TOTAL to the ResultTable table and populates it with totals
for each numeric column. Copies the metadata from the Table1 table to
the ResultTable table.
TableAddTotalRow.r
Adds a row named TOTAL to the ResultTable table
and populates it with totals for each numeric column. Copies the metadata
from the Table1 table to the ResultTable table.
TopNPlusOther.r
Reduces the Table1 dataset into a ResultTable
dataset which contains the top N categories from the source table, and
a row named ‘Other’ which contains a sum of the values for the other categories.
For example, given a category count of 3, and the following source table…
NAME
VALUE
A
30
B
20
C
10
D
3
E
2
F
1
… the result table will be:
NAME
VALUE
A
30
B
20
C
10
Other
6
The script has a number of default values.
If required, these may be overwritten by adding new properties to the
Execute R action, using the Define
Action Parameters Wizard. The properties used by the script, and their
default values are as follows:
Property
Default Value
CategoryCount (Integer)
3
OtherCategoryName
(String)
Other
SourceValue (String)
VALUE
The ‘CategoryCount’ value should not exceed
the number of rows in the source table.
Running a Script from the
Statements Parameter
To run a script
from the Execute R action’s Statements parameter, use the R source() and
paste() functions as follows: