This article describes how to go through your document and hide variable sets that have a large number of categories. You may specify the number of categories that you wish to consider large. This can be helpful when you wish to automatically create a large number of tables using one of the built-in functions such as Banner Tables, Summary Tables, Crosstabs, etc. and some of the resulting tables would be too large and hence unhelpful. Rather than sorting through your list of variable sets to determine which to keep, you can use this QScript to first hide any variable sets that would generate large tables.
Requirements
- If customizing more outside the automated settings, a Displayr Enterprise user license which includes the ability to add custom analysis menu items and QScripts. See How to Use QScripts in Displayr for more details.
Method - Anything menu
To hide: click Anything > Hide/Unhide > Hide Data with Many Categories
To unhide: click Anything > Hide/Unhide > Unhide Data with Many Categories
Method - Custom QScript
To run the QScript to hide variable sets:
- From the toolbar menu, select Anything > [Your account name] > Open QScript Editor.
- Paste the following code into the QScript editor:
// Hide questions with a large number of categories includeWeb("QScript Selection Functions"); includeWeb("QScript Data Reduction Functions"); includeWeb("QScript Functions to Generate Outputs"); if (!main()) log("QScript Cancelled."); else conditionallyEmptyLog("A description of the hidden questions has been added to your report.") function main() { var data_files = dataFileSelection(); var report_message = "The following questions have been hidden. To unhide them, select Automate > Browse Online Library > Hide/Unhide > Unhide Large Questions."; var hidden_tag = "Hidden - Large number of Categories"; var max_categories = 20; max_categories = prompt("Specify the maximum number of categories to keep:", max_categories); var hidden_questions = []; var candidate_questions = getAllQuestionsByTypes(data_files, ["Pick One", "Pick One - Multi", "Pick Any", "Pick Any - Grid", "Pick Any - Compact"]); candidate_questions = candidate_questions.filter(function (q) { return !q.isHidden; }); candidate_questions.forEach(function (q) { if (largestDimension(q) > max_categories) { q.isHidden = true; hidden_questions.push(q.name); q.name = q.name + " " + hidden_tag; } }); if (hidden_questions.length > 0) { var new_group = project.report.appendGroup(); new_group.name = "Hidden Questions"; var report = simpleHTMLReport([report_message].concat(hidden_questions), "Hidden Questions", new_group, true, false); return true; } else { log("No large questions to hide."); return false; } }
- Click the Play button in the QScript Editor toolbar to run the QScript:
- At the next prompt, enter a value for the maximum number of categories in a variable set and click OK. Any variable set which contains more categories that the value specified will be hidden.
- If you want to save the QScript for future use, click OK then enter a file name for the QScript and click OK. This will save the QScript to your Displayr cloud drive and will then be available in all of your documents by selecting Anything > [Your account name] > Open QScript from Displayr Cloud Drive > [QScript Name]. If you don't wish to save the QScript to the cloud drive, click Cancel in the QScript Editor.
To unhide variable sets, follow the same steps above with the following QScript code:
includeWeb("QScript Selection Functions"); main(); function main() { var hidden_tag = "Hidden - Large number of Categories"; var data_files = dataFileSelection(); var candidate_questions = []; data_files.forEach(function (data_file) { candidate_questions = candidate_questions.concat(data_file.questions.filter(function (q) { return q.isHidden && q.name.indexOf(hidden_tag) > -1; })); }) if (candidate_questions.length == 0) { log("No questions to unhide."); return false; } else { candidate_questions.forEach(function (q) { q.isHidden = false; q.name = q.name.replace(hidden_tag, ""); }); log(candidate_questions.length + " question" + (candidate_questions.length == 1 ? " was " : "s were ") + "unhidden."); return true; } }
Note that this QScript will only unhide variables sets that were hidden using Hide Variables Sets with Many Categories QScript from above and will not affect variable sets that were not originally hidden by this method.
Next
How to Hide a Category in a Pick One Variable Set
How to Hide/Unhide Variables Sets Selected from a List
How to Unhide All Hidden Questions
How to Use QScripts in Displayr
How to Create a Custom QScript