QScript ROutput

From Q
Jump to: navigation, search


R Outputs are an output generated by R, and are located in the Report. See Using R in Q for more details.

To create an R Output in QScript, use appendR() in the ReportGroup object you want to append the item to in your report.


The R code which gets executed.


An interface that enables the querying of an R Output's data


Deletes a table, plot or sub-group.


Returns an array containing the variables, questions, tables, R items, or other items that are used when calculating this object. A Table object will return an array containing the questions it is a crosstab for, and any variables used as filters or weights. An ROutput object will return other ROutput objects used in its calculations. A JavaScript Variable object will return the variables referenced in its formula, etc.
recursiveOptional. If true then it will return all the objects that are normally returned, as well as all objects that those objects depend on, and so on.
Returns:Returns an array containing Question objects, Variable objects and AnalysisItem objects.


Whether two objects are the same.
Returns:true or false


Errors with the R code or found in the execution of the R code. A string. Returns null if there is no error.

exportToExcel(filename, options)

Exports an item or group to Excel. This method is currently only available in desktop Q.
filenameThe name of the exported file.
optionsAn optional dictionary of options to pass to the function. These map to the settings in the Table Options dialog when exporting in Q using the fast Excel export option:
table_style: The name of an Excel-based table style to use for the export. See the dropdown in the Q Excel export dialog for names - remove the spaces when used here.
notes: Text that appears as a comment in the first cell of every sheet.
hyperlink: A link applied if the project is uploaded as a Dashboard.
ignore_net_and_sum: Excludes the NET and SUM columns or rows from the exported table.
export_tables_as: When exporting multiple tables, how they should be laid out:
- OneWorksheetPerTable: each table is placed on a new worksheet.
- OneWorksheetPerGroup: tables in the same group are placed on the same worksheet.
- OneWorksheet: all tables are placed on a single worksheet.
how_count: For multiple tables on the same worksheet, how they should be spaced:
- BetweenTops: use a fixed number of rows between the tops of tables.
- FromBottomOfOneToTopOfNext: leave a number of rows between the bottom of one table and the top of the next.
num_rows_between_tables: The number of rows used by how_count
include_table_of_contents: Whether to include a table of contents
perform_statistical_test_of_independence: Whether to perform a statistical test of independence for the entire table (NB: this is in addition to the tests automatically shown on tables).
repeat_headings: Whether to repeat headings for each table.
show_significance_arrows: Whether to include significance arrows (when shown in table).
table_names_sequential: Whether to name tables sequentially (e.g. Table 1, Table 2, etc.).
show_column_comparisons_in_separate_row: Whether to show column comparisons in a separate row.
project.report.exportToExcel('output.xlsx', {
  table_style: 'TableStyleLight1',
  notes: 'Notes',
  include_table_of_contents: true,


Get/sets the list of Variable objects to apply as filters for this analysis item.
t.filters = [data_file.getVariableByName('awarenessCoke')];
t.filters = [];


Returns the value of the named GUI control in the R Output. Warning: The GUI code only runs until the first validation error. Thus if the user has not entered valid values for all controls then some controls may be unavailable.
control_nameThe name of the control, as supplied when it was created. It will have a default name if no name was supplied when it was created.
Returns:The type of the value returned depends on the type of the control: true/false for checkboxes, text for textboxes, text or Question or Variable or Item for dropboxes, number for numeric up/down, etc. If no input with the given name exists then null is returned. If the user has entered nothing, but the control has a default, then the default is returned. Otherwise null is returned.


Get the ReportGroup object that contains this table/plot/group.


Get the internal identifier for this object, which is unique for all objects in the Report.


Gets/sets the height of the item in pixels


Gets/sets whether this item is hidden from exported views in Displayr. If an item is hidden from exported views, then when you share or export the project, the item will not appear in the shared page or exported document. This is typically used if you are using R Outputs for intermediate steps in calculating values, and these steps would be irrelevant or confusing for the person viewing the page.
routput1.hiddenFromExportedViews = true;


Gets/sets the left position (i.e. X position) of the item in pixels


Messages produced in the execution of the R code. A string. Returns null if there are no messages.


Get/set the name for this object, as it appears in the Report.


Returns an array of strings, which are the R classes of the output of this R calculation. If the R Output is in error then an exception will be thrown. If the R Output is not in Automatic mode and the R code has not been calculated before, null will be returned (and you may call update() in QScript in order to force the R code to be calculated).


Get/set the reference name for this object, that is used to reference this object in the source code of other objects.


Sets the javascript code that defines the input controls for an item.

setGuiControlInputRaw(control_name, value)

Sets the value of the named GUI control in the R Output to the value provided as a string Warning: This sets the value directly, and will allow you to place invalid values into the fields.
control_nameName of the GUI control to update.
valueValue to set the control. To make this parameter refer to a variable, question, or output then it must be set to the GUID of the reference.
var text_vars = project.dataFiles[0].variables.filter(function(v)
{ return v.variableType == "Text"; }
var x = project.report.subItems[0];
x.setGuiControlInputRaw("formtextvar", text_vars[2].guid);


A textual representation of the table associated with the R code.


Textual output of the R code. Returns null if the item has not produced text output, or perhaps is in error.


Gets/sets the top position (i.e. Y position) of the item in pixels


Returns "R Output".


Force the evaluation of the R code.


Controls how the R Output should be updated each time it is viewed: "Manual" - only update when forced "Automatic" - if the R Output's inputs have changed, update it when viewed


Warning messages produced in the execution of the R code. A string. Returns null if there is no warning.


Gets/sets the width of the item in pixels