QScript Table

From Q
Jump to: navigation, search


A table or crosstab. Assign Question objects to primary and (optionally) secondary. Can also show raw data.


Updates the appearance of a plot using a template file. Template files are created manually from within Q.
template_fileThe path to a Q template file. If this is a relative path then it is relative to the running script's directory. If you are running the script on Displayr then this should be the ID returned by /API/Upload after you uploaded a template file. If you change a table to a plot then the Table object you used to have will stop working. Instead use the object returned by this method.
Returns:The (perhaps new) Plot object.
var plot = table.applyTemplate('Snake.QTemplate');


Calculates the table/crosstab and returns a TableOutput object, which you can interrogate for its row labels, column labels, and statistical values.
// Change the name of the table to include the category which has the lowest (most significant) p-value.

// Calculate the statistics.
var output = table.calculateOutput();

// Get the array of p-values.
var pvalues = output.get('p');

// Keep track of which row contains the lowest p-value.
var lowest_p;
var lowest_row;

for (var row = 0; row < output.numberRows; row++)
    for (var column = 0; column < output.numberColumns; column++) {
        var p = pvalues[row][column];
        if (row == 0 && column == 0) {
            lowest_p = p;
            lowest_row = row;
        } else {
            if (p < lowest_p) {
                lowest_p = p;
                lowest_row = row;
// Now 'lowest_row' holds the number of the row with the lowest p value.
// Lets extract its label from the output.
var lowest_row_label = output.rowLabels[lowest_row];

// Change the name of the table to include the lowest row information.
table.name = table.name + ' (Most significant: ' + lowest_row_label + ', p = ' + lowest_p + ')';


Gets/sets the statistics shown in cells for this table. Unknown statistics, or those not valid for this table/crosstab, will be ignored. Use the English names of statistics you see in the Q desktop program.
table.cellStatistics = ['%', 'n']


Increases or decreases the number of decimal places shown in the table or plot. This is equivalent to pressing the buttons in the toolbar to increase or decrease the number of decimal places shown.
deltaThe change in the number of decimal places shown.


Gets/sets the statistics shown at the bottom of each row. Unknown statistics, or those not valid for this table/crosstab, will be ignored. Use the English names of statistics you see in the Q desktop program.
table.columnStatistics = ['Column n']


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

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 = [];


Gets the number of decimal places shown in the table or plot for the specified statistic.
statisticThe statistic name in English.


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


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


Gets/sets the main Question object to plot/tabulate.


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


Gets/sets the statistics shown to the right of each row. Unknown statistics, or those not valid for this table/crosstab, will be ignored. Use the English names of statistics you see in the Q desktop program.
table.rowStatistics = ['Row Population']


Provides an object you can use to add or remove Rules from a table or plot.


Gets/sets the second Question object to crosstab against. It can also be "SUMMARY" or "RAW DATA".

setDecimalPlaceFor(statistic, place)

Sets the number of decimal places shown in the table or plot for the specified statistic.
statisticThe statistic name in English.
placeThe number of decimal places, which has to be an integer from 0 to 13.
setDecimalPlaceFor("Average", 1);


Gets/sets whether to show the percent sign next to percentages in the table or plot. Changing this property is equivalent to toggling the percent sign button in the toolbar.
table.showPercentSign = false; // percent signs will not be shown next to percentages in table.


No longer supported.


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


Gets the Translations object for this item, allowing you to override the names used for (for example) statistics, NET, SUM, etc.
log(item.translations.get('Column n'));


Returns "Table".


Gets/sets the Variable object to be used as a weight for this table/plot. Assign null to remove any weight previously applied.
t.weight = project.dataFiles[0].getVariableByName('weight');
t.weight = null;


Gets/sets the width of the item in pixels