What a capsule says of its data: where each file came from, the schema of its tables, summaries that show drift later, the environment of the run, and commitments.
Each section is one help page: what its functions are for, and the
example of the page as it runs. ?name gives the arguments
and the value in full.
nqdata(), nqdadd(), nqdput(),
nqdcheck(): A capsule’s data record,
noqtis.data.json in its folder, says where each data file
came from, the schema of its CSV files, summaries that show drift later,
and the steps and checks made with it (the format
noqtis-data-1). It is a file of the capsule like any other:
seal the folder (nqseal()) after changing the record, and
the seal covers it. The record is canonical JSON, the same bytes the
noqtis tool and every other binding write.
d <- file.path(tempdir(), "cap")
dir.create(file.path(d, "data"), recursive = TRUE)
writeLines(c("x,y", "1,a", "2,b"), file.path(d, "data", "a.csv"))
nqdadd(d, "data/a.csv", url = "https://example.org/a.csv")
nqdata(d)
#> [1] "{\"format\":\"noqtis-data-1\",\"sources\":[{\"path\":\"data/a.csv\",\"sha256\":\"01331cf653a16b7278f66569b5719303c2f18ce869c87638c09943a49d3e73dd\",\"size\":12,\"url\":\"https://example.org/a.csv\"}]}"
nqdcheck(d)
#> check ok detail
#> 1 record TRUE noqtis-data-1, canonical: 1 sources, 0 schemas
#> 2 source TRUE data/a.csv: SHA-256 and size match
unlink(d, recursive = TRUE)nqdaddr(), nqdverify(),
nqdfield(), nqdrslv(),
nqdreply(), nqdwayback(): A source of the data
record names where its file came from. These functions make no network
request: they say what to fetch and read what came back, as the
noqtis src command does (the C functions are
nqdaddr(3)).
rs <- '{"base":"https://data.example.org","id":"abcd-1234","kind":"socrata"}'
nqdrslv(rs)
#> [1] "https://data.example.org/api/views/abcd-1234.json"
nqdreply(rs, charToRaw('{"id":"abcd-1234","name":"Crimes"}'))
#> [1] "https://data.example.org/api/views/abcd-1234/rows.csv?accessType=DOWNLOAD"
#> [2] ""
nqdwayback("http://web.archive.org/web/2024/https://example.org/a.csv")
#> [1] "https://web.archive.org/web/2024id_/https://example.org/a.csv"nqschema(), nqschk():
nqschema() reads each CSV file (RFC 4180) and returns its
schema as JSON: the columns, the narrowest type each fits
(bool, int, real,
date, text; a leading zero keeps a code text),
whether each has missing values ("" and NA),
the number of rows, and with ranges each number and date
range. With put, it records them in the data record
instead. nqschk() checks the files against the schemas the
record pins: header, types, missing values, ranges, sets, row counts and
rules (add rules with nqdput()).
d <- file.path(tempdir(), "sch")
dir.create(d)
writeLines(c("id,when", "1,2024-01-02", "2,2024-02-29"),
file.path(d, "a.csv"))
nqschema(d, "a.csv")
#> [1] "{\"columns\":[{\"name\":\"id\",\"nulls\":false,\"type\":\"int\"},{\"name\":\"when\",\"nulls\":false,\"type\":\"date\"}],\"kind\":\"csv\",\"path\":\"a.csv\",\"rows\":{\"max\":2,\"min\":2}}"
nqschema(d, "a.csv", put = TRUE)
nqschk(d)
#> check ok detail
#> 1 schema TRUE a.csv: 2 rows, 2 columns as the schema says
unlink(d, recursive = TRUE)nqdpin(), nqdrift(): nqdpin()
records in the data record summaries of each CSV file, of a fixed size
whatever the file’s: for a numeric column a quantile sketch of 1,001
points (every distinct value when there are at most 1,001), the
population stability index’s decile bins and first-digit counts; for any
other column the counts of its 1,000 most frequent values.
nqdrift() compares each summarised file (or
current, a later copy) with its summary: the two-sample
Kolmogorov-Smirnov test, PSI and Jensen-Shannon divergence, the
chi-square test of homogeneity, and Benford’s first-digit test. The
tests and their error are defined in the manual page
noqtis-drift(1); on the test vectors they match R’s
stats::ks.test() and stats::chisq.test() to
1e-9.
d <- file.path(tempdir(), "dft")
dir.create(d)
write.csv(data.frame(x = round(stats::qnorm(ppoints(200)), 6)),
file.path(d, "a.csv"), row.names = FALSE, quote = FALSE)
nqdpin(d, "a.csv")
nqdrift(d)
#> check ok
#> 1 drift TRUE
#> 2 drift TRUE
#> detail
#> 1 a.csv: 200 rows then 200
#> 2 a.csv: x: n 200 then 200; KS D 0.0000 (asymptotic, p 1), PSI 0.0000, JS 0.0000, Benford p 0.183
#> stats
#> 1 <NA>
#> 2 {"path":"a.csv","name":"x","nref":200,"ncur":200,"nullsref":0,"nullscur":0,"kind":"num","ksd":0,"ksp":1,"kserr":0,"ksexact":false,"psi":0,"js":0,"benfordx2":11.342083789445448,"benfordp":0.18305928593542317,"benfordpref":0.18305928593542317,"level":"ok"}
unlink(d, recursive = TRUE)nqdparse(), nqdschk(),
nqdsyn(), nqdcal(), nqdchunk(),
nqdpiece(): nqdparse() reads JSON text as a
data record, as noqtis data check reads one, and returns it
in canonical form (an error says what is wrong and where).
nqdschk() checks the CSV file of one "schemas"
element against it. nqdsyn() writes a synthetic stand-in
for a CSV file from the schema the record pins for it (the same bytes
for the same seed) and records it as a synthetic source; real data is
never replaced. nqdcal() calibrates the drift warnings of a
file’s summary on files known not to have drifted from it, so
nqdrift() then warns only beyond what they showed.
nqdchunk() records the SHA-256 of each run of
chunk bytes of a large file, and nqdpiece()
checks a piece of that file (the bytes from off on) against
them, reading only the piece.
d <- file.path(tempdir(), "dx")
dir.create(file.path(d, "data"), recursive = TRUE)
writeLines(c("id,x", "1,0.5", "2,1.5", "3,2.5"), file.path(d, "a.csv"))
nqdparse('{"format":"noqtis-data-1"}')
#> [1] "{\"format\":\"noqtis-data-1\"}"
s <- nqschema(d, "a.csv")
attr(nqdschk(d, s), "ok")
#> [1] TRUE
nqdput(d, "schemas", sub('"a.csv"', '"data/s.csv"', s, fixed = TRUE))
nqdsyn(d, "data/s.csv", seed = 7)
readLines(file.path(d, "data", "s.csv"))
#> [1] "id,x" "764,0.4218805665407275" "745,0.6702572626570436"
#> [4] "284,0.11856762281140665"
nqdpin(d, "a.csv")
invisible(nqdcal(d, "a.csv", file.path(d, "a.csv")))
writeBin(as.raw(rep(0:255, 8)), file.path(d, "big.bin"))
invisible(nqdchunk(d, "big.bin", chunk = 1024))
p <- tempfile()
writeBin(as.raw(rep(0:255, 4)), p)
attr(nqdpiece(d, "big.bin", p, off = 1024), "ok")
#> [1] TRUE
unlink(c(d, p), recursive = TRUE)nqdenv(), nqdpkgs(): nqdenv()
records in the data record’s "env" the environment of a
run, as noqtis env does (the platform, the noqtis version,
the locale and time zone, the SHA-256 of the lock files at the top of
dir, the random number generator and its seed), and fills
the runtime: R, its version, and the packages. nqdpkgs()
lists the packages: by default those loaded in this session, each with
its version and where it came from ("CRAN" or the
repository its description names, "github" and the like for
a remote install, "base" for R’s own, else
"local"). Nothing is fetched.
d <- file.path(tempdir(), "env")
dir.create(d)
writeLines("{}", file.path(d, "renv.lock"))
head(nqdpkgs())
#> name version source
#> 1 base 4.6.2 base
#> 2 bslib 0.12.0 RSPM
#> 3 buildtools 1.0.0 local
#> 4 cachem 1.1.0 RSPM
#> 5 cli 3.6.6 RSPM
#> 6 compiler 4.6.2 base
e <- nqdenv(d, seed = 42)
substr(e, 1, 60)
#> [1] "{\"os\":\"linux\",\"arch\":\"x86_64\",\"noqtis\":\"0.3.0\",\"locale\":\"en_"
unlink(d, recursive = TRUE)nqdcommit(), nqdreveal(),
nqdcite(), nqdreport():
nqdcommit() commits to some content (a randomisation list,
an analysis plan) in the data record, as noqtis commit
does: the record gets the SHA3-256 of the content under a fresh 32-byte
secret salt, which is returned; keep the salt and the content out of the
capsule until the reveal, and seal the capsule (with a timestamp) so the
commitment is dated. Without the salt the record says nothing of the
content. nqdreveal() finds the commitment that content and
salt match, comparing every recorded digest in constant time.
nqdcite() writes how to cite the data, from the record’s
"cite". nqdreport() checks the capsule and its
record and writes a report of both, as noqtis report
does.
d <- file.path(tempdir(), "cm")
dir.create(d)
writeLines("x", file.path(d, "a.txt"))
s <- nqdcommit(d, "arm A: 1, 4\narm B: 2, 3\n", kind = "randomisation")
nqdreveal(d, "arm A: 1, 4\narm B: 2, 3\n", s)
#> [1] 1
nqdreveal(d, "something else", s)
#> [1] NA
nqdput(d, "cite", '{"title":"T","authors":["A. Author"],"year":2026}')
cat(nqdcite(d))
#> cff-version: 1.2.0
#> message: "Cite this data as below."
#> type: dataset
#> title: "T"
#> authors:
#> - name: "A. Author"
#> date-released: "2026-01-01"
k <- nqkeygen("ML-DSA-44")
nqseal(d, k$sk, k$pk, "ML-DSA-44")
cat(nqdreport(d, k$pk, format = "txt"))
#> noqtis report: /tmp/RtmplmPFEA/cm
#> Passed: 0 of 23 checks failed
#>
#> Capsule:
#> ok seal.read noqtis.sig
#> ok seal.parse a JSON object
#> ok seal.canonical canonical JSON
#> ok seal.fields the fields of noqtis-seal-1
#> ok seal.format "noqtis-seal-1"
#> ok seal.alg ML-DSA-44
#> ok seal.context "noqtis-capsule-1"
#> ok seal.key a public key of the right size
#> ok seal.signature a signature of the right size
#> ok manifest.read noqtis.json
#> ok manifest.digest SHA-256 of noqtis.json matches the seal
#> ok key the seal's key is the trusted key
#> ok signature ML-DSA-44 signature over noqtis.json is valid
#> ok folder listed
#> ok file a.txt
#> ok file noqtis.data.json
#> ok manifest.parse a JSON object
#> ok manifest.canonical canonical JSON
#> ok manifest.fields the fields of noqtis-capsule-1
#> ok manifest.format "noqtis-capsule-1"
#> ok manifest.created 2026-11-21T23:23:48Z
#> ok manifest.order files sorted by path, no repeats
#>
#> Data:
#>
#> Commitments:
#> randomisation - 2026-11-21T23:23:48Z - d68443e15ce374e177d18c9a8b962c2d2a4f1f2c3a22fcab9db302d28b077f59
#>
#> Citation:
#> title: T
#> authors: A. Author
#> year: 2026
#>
#> Checks:
#> ok data.record noqtis-data-1, canonical: 0 sources, 0 schemas
unlink(d, recursive = TRUE)