DataStep Studio for R Install
Documentation · version 0.10.3

How-to guide

Short recipes for everyday work, each with the key in the editor and the dsr command for a terminal.

On this page
Recipes
  1. Run only what I changed
  2. Find out why a variable has a wrong value
  3. Look inside a run that failed
  4. Stop a loop at one subject
  5. See which pipeline step loses records
  6. Find which line of a function made a value
  7. Compare my data set with a second programmer's
  8. Check a table against the CSR
  9. Count subjects, not records
  10. Find the mistakes before running
  11. Tidy a program without changing what it does
  12. Prove a program runs on its own
  13. Let Claude Code work in my session

Short recipes for everyday work. Each names the key or command in the editor and the dsr command that does the same in a terminal of the editor (where an AI agent works too). The manual explains each tool in full.

Run only what I changed

After one full run the objects stay in the session. Select the lines and press Cmd/Ctrl+Enter, or run a range:

dsr run prog.R --from-line 12 --to-line 30

A range runs whole expressions. Run to Line and Run from Line (right-click in the editor) do the same from the cursor.

Find out why a variable has a wrong value

Stop the run where the value is made, for the record you care about:

dsr run prog.R --stop-at 'R/derive.R:5 if any(bmi == 30)'
dsr pry eval 'bmi'
dsr pry next
dsr pry eval 'grp[bmi == 30]'
dsr pry quit

In the editor: a breakpoint in the margin with a condition (right-click the red dot), then F5; or the cursor on the line and Stop at Line (Cmd/Ctrl+Alt+F9). The stop works inside a function too.

Look inside a run that failed

An ERROR keeps the frames where it happened:

dsr pry stack
dsr pry ls
dsr pry eval 'summary(weight)'

The editor opens the same frames in the Pry panel.

Stop a loop at one subject

Write the stop into the program and run it as always:

for (i in seq_len(nrow(dm))) {
  pry(when = dm$USUBJID[i] == "S-110")
  ...
}

pry(stop = FALSE) keeps a snapshot and goes on; dsr pry points lists the snapshots.

See which pipeline step loses records

Put the cursor on the pipeline and run Debug the Pipeline at the Cursor, or:

dsr pipe programs/adam/ad_adsl.R:42

Each step shows its rows before and after, the columns it added or dropped, and the records it dropped (by USUBJID and the sequence number). dsr data '@pipe[1]:dropped' lists them.

Find which line of a function made a value

dsr trace --call 'bmi_group(c(24, 30, 31))'

Every line that ran, the variables it changed, each if with the values it compared. In the editor: Trace Function Call, or Call a Function with a Form to fill in the arguments.

Compare my data set with a second programmer's

dsr compare adsl adsl_ref --key USUBJID

As PROC COMPARE: the rows and columns only in one, and each value that differs, with examples. In the editor: Compare Two Data Sets. A file works too: .rds, .xpt, .sas7bdat, .csv.

Check a table against the CSR

dsr numbers output/t14_3_01.txt csr.txt --table 14-3.01

Row by row and number by number at the reference's decimals: NUMBERS: MATCH or each difference with its line. --round sas when the reference was rounded by SAS; --page 49 for a page of a PDF.

Count subjects, not records

dsr freq adae AEDECOD --subjects

--by TRT01A gives percents within each arm; dsr means adsl AGE --by TRT01A gives n, mean, SD, min, median, max.

Find the mistakes before running

Save the file: lint marks functions that do not exist in your installed packages, argument names a function does not have, and names with a typo, each with "did you mean". Or for a folder:

dsr lint programs

Tidy a program without changing what it does

Format Document (Shift+Alt+F), or:

dsr format prog.R

The file is written only when its tokens and comments are the same before and after; --check writes nothing.

Prove a program runs on its own

dsr batch prog.R

A new R session for each program, as a production run, and prog.log next to it. --vanilla leaves out the project's .Rprofile.

Let Claude Code work in my session

DataStep R: Set Up Agent Tools writes the MCP configuration of the project. Or in a terminal of the editor, where dsr is on the PATH, tell the agent to read dsr guide once. Its runs and stops show in your R Console and editor. The other agents: the page Set up an agent.