Adding Data Files

From Q
Jump to navigation Jump to search

This page describes how to add files programmatically. See Multiple Data Files for instructions for adding a data file from the menus. Adds a data file to a project.

// Add phone.sav as an extra data file to the current project.
var data_file = project.addDataFile("phone.sav", null, { auto_tidy_labels: true,
                                                         auto_detect_questions: false,
                                                         strip_labels_html: true });

This code imports the phone.sav data file and assigns the resulting project to a variable. Key aspects of the code are:

  • project.addDataFile("phone.sav", null, true, false, true) causes the phone.sav file to be imported, where the first true indicates that the labels in the file are to be auto-tidied, the false indicates the questions are not to be auto-detected and the true at the end indicates that HTML should be removed from any labels.
  • null could be replaced by an ID if using the HTTP API.
  • var data_file = project… assigns the data file to a variable called data_file. Later code then uses this variable. Importantly, variable in this context just means an object of some kind; it is a much more general concept that the idea of a column of data in a data file.


See also