This describes how to use a QScript to remove all changes made by How to Add Variable Names And Values to Labels in your project and is only intended for this purpose. This script looks for a special invisible character in the labels and will have no affect in the absence of this character (i.e., if you manually modify labels and inadvertently remove the hidden character, then this QScript will not work).
Requirements
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.
Please note these steps require a Displayr license.
Method
To run the QScript to hide variable sets selected from a list:
- From the toolbar menu, select Anything > [Your account name] > Open QScript Editor.
- Paste the following code into the QScript editor:
includeWeb("QScript Functions to Generate Outputs"); if (!main()) log("QScript Cancelled."); else conditionallyEmptyLog("QScript Finished."); function main() { includeWeb("QScript Utility Functions"); var hidden_char = "\u200b "; project.dataFiles.forEach(function (data_file) { data_file.questions.forEach(function (question) { if (!question.isBanner && question.isValid) undoVariableNameAndValueAddition(question, hidden_char); }) }); return true; } // Looks for hidden_char in labels and removes averything that comes // before it. This includes: // 1. Question names. // 2. Variable Labels. // 3. Data reduction labels. function undoVariableNameAndValueAddition(question, hidden_char) { var variables = question.variables; var data_reduction = question.dataReduction; var question_type = question.questionType; // Remove Variable Name from Question Name var split_q_name = question.name.split(hidden_char); if (split_q_name.length == 2) question.name = preventDuplicateQuestionName(question.dataFile, split_q_name[1]); // Values to Category Labels (Pick One, Pick One - Multi) if (question_type.indexOf("Pick One") == 0) { var codes = (question_type == "Pick One" || (question_type == "Pick One - Multi" && !data_reduction.transposed)) ? data_reduction.rowLabels : data_reduction.columnLabels; codes.forEach(function (code) { var split_code = code.split(hidden_char); if (split_code.length == 2) data_reduction.rename(code, split_code[1]); }); } // Remove Variable Names from Variable Labels (and corresponding data // reduction labels where relevant) variables.forEach(function (v) { var split_label = v.label.split(hidden_char); if (split_label.length == 2) v.label = split_label[1]; }); var mr_types = ["Pick One - Multi", "Number - Multi", "Pick Any"]; if (mr_types.indexOf(question_type) > -1) { var by_columns = (question_type == "Pick One - Multi" && !data_reduction.transposed); var codes = by_columns ? data_reduction.columnLabels : data_reduction.rowLabels; codes.forEach(function (code) { var split_code = code.split(hidden_char); if (split_code.length > 1) data_reduction.rename(code, split_code[split_code.length - 1]); }); } }
- Click the Play button in the QScript Editor toolbar to run the QScript:
- 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.
Next
How to Add Variable Names And Values to Labels
How to Hide a Category in a Pick One Variable Set
How to Hide/Unhide Questions with Many Categories
How to Unhide All Hidden Questions
How to Use QScripts in Displayr
How to Create a Custom QScript