Text Analysis - Advanced - Save Variable(s) - Tidied Text
Jump to navigation
Jump to search
Displayr - Anything Menu
Extensions
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library > QScript Online Library
R Online Library
Text Analysis
Text Analysis - Advanced
User Interface > Create Text Analysis
Save a variable to the data set that contains the tidied text
Save the tidied text which has been processed by Text Analysis - Advanced - Setup Text Analysis as a new variable in the data set. This blog post describes saving tidied text in order to create a word cloud.
Usage
To use this item, first select an item created by Text Analysis - Advanced - Setup Text Analysis .
Code
includeWeb("QScript Utility Functions");
includeWeb("QScript Functions to Generate Outputs");
includeWeb("QScript R Output Functions");
includeWeb("QScript Selection Functions");
if (fileFormatVersion() < 9.11)
log("This script requires a newer version.")
else
main();
function main() {
var bad_selection_message = "Select an item that has been created using Text Analysis > Setup Text Analysis.";
var web_mode = (!!Q.isOnTheWeb && Q.isOnTheWeb());
var selected_item = getSelectedROutputFromPage(["wordBag"]);
if (selected_item === null) {
log(bad_selection_message);
return false;
}
var source_question = selected_item.getInput("formtextvar");
var target_data_file = source_question.dataFile;
var r_expression = "library(flipTextAnalysis)\r\n"
+ "tidied.text = SaveTidiedText(" + stringToRName(selected_item.referenceName) + ")";
var new_q_name = preventDuplicateQuestionName(target_data_file, "Tidied Text from " + selected_item.name);
var new_var_name = cleanVariableName(selected_item.name) + "_tidied_text";
new_var_name = preventDuplicateVariableName(target_data_file, new_var_name);
try {
var new_var = target_data_file.newRVariable(r_expression, new_var_name, new_q_name, null);
} catch (e) {
log("Save Tidied Text could not be created from this item: " + e);
return false;
}
var new_question = new_var.question;
// In Q, select the table showing the new variable.
if (!web_mode) {
var new_group = generateGroupOfSummaryTables(new_q_name, [new_question]);
project.report.setSelectedRaw([new_group.subItems[0]]);
}
return true;
}
See Also
Displayr - Anything Menu
Extensions
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library > QScript Online Library
R Online Library
Text Analysis
Text Analysis - Advanced
User Interface > Create Text Analysis