The following script checks to see if a data file has already been imported into the project and, if it has, it stops the script from running and tells the user “Run this script from a fresh copy of Q, with no project open.”:
assert(project.dataFiles.length == 0, "Run this script from a fresh copy of Q, with no project open.");
- project.dataFiles returns the data files in the project as an array (which is basically a list).
- project.dataFiles.length works out the length of the array of data files (i.e., counts the number of data files in the project).
- project.dataFiles.length == 0 returns a true of the number of data files is 0 and a false otherwise.
- assert(condition,message) checks that condition is true. If not your script will be aborted.
See also
- Next worked example.
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.