Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Scripts

The Scripts page holds every script of the project in one place: the scripts the prepare steps run, the analyses kept from the Custom tab of the Analysis page, and any other R or Python file in scripts/ or analyses/. Beside a step in the Add data step of the Set up page, Script shows the script’s code under the step, with a link to it here.

The list

The bar above the list narrows it, as on the Datasets page. A script belongs to the datasets its steps write, and an analysis to the datasets it uses, so the Search box finds a script by its path, its steps’ names, commands, inputs and outputs, or an analysis’s request, and the filters choose by the Study, Wave, Reporter and Modality of those datasets, and by the lab’s own dataset fields. Three more are the page’s own: Stage (clean, process, extract, score, no stage, analyses, or not run), Status (of the steps that run it: up to date, outdated, missing output, missing input) and Language. The study chosen at the top of the window is where the filters start. A script that writes no dataset of the project stays in the list whatever study, wave, reporter or modality is chosen.

The scripts are listed on the left; click one to open it.

A script

The top shows the script’s code with its syntax coloured. Beside it, What it gets and gives lists each step that runs it with its command, what it reads and what it writes, and for each dataset it writes, its ID column, the columns its column map names and its missing codes. Change it there and press Save, or press Open in your editor to edit it in the program your computer opens it with. Saving a script puts the steps that run it out of date, since the script is one of their inputs. Choosing another script with unsaved changes asks first.

For a script that steps run, Steps that run it lists them as on the Add data step, each with its status, command, inputs and outputs, Run and Log, and two more buttons:

Add a step adds a step that runs the script, starting from a command such as Rscript scripts/tidy.R INPUT OUTPUT for you to fill in. A step is checked before it is written, and refused if it would cause a problem, such as a step that writes its own input. Below the steps, the Log shows what the last step printed.

For an analysis, the panel shows what was asked for, its datasets and variables, and Delete, which deletes the script and its entry under analyses. It runs on the Custom tab.

When the project is in git, as every DataLad dataset is, History at the bottom lists the script’s commits, newest first, with any change not yet saved as a version on top; open one to see what changed. The script is saved with the data in the same versions (see Data versions), and a step run through DataLad records which version of the script made its files.

New scripts

New script asks for the script’s Stage and language, R or Python, then what it works on:

A script for a stage begins with what it reads and writes: the command its step runs, the dataset’s file, ID column, the columns its column map names and its missing codes. Only the function, or the query, is left to write; the lines after it apply it to the files, reading every cell as text and writing it back as it was, as labcatalog reads a file, so IDs keep their leading zeros and empty cells stay empty. The rule that finds each person’s file reads **/, * and ? as a folder dataset’s files does. Its step, with its stage, is added to labcatalog.yaml with it, after the same check as Add a step.

Draft a cleaning step, at the bottom of the page, has a language model write a cleaning script for a dataset; see Register Prepare Steps. Draft a summary step, below it, has a language model write the features() of an extract script over a folder dataset’s files, such as a computer task’s trials, and draft the instrument of its measures; see Record a Computer Task.