The AI kit (tflspec_ai_manual()) asks the assistant for one answer
holding every file of the study's YAML spec: each file a heading with its
path (### spec/outputs/T-1.yml) and its content in a ```yaml
block, the way the kit's example (06_example_spec.md) is written.
tfl_ai_unpack() writes those files into a study folder, ready for
tfl_ai_review() and the study's other functions
(tfl_read_study_spec(), tfl_read_outputs()).
Arguments
- answer
The answer: its text (a character vector, one element a line or the whole text), the path of a
.md/.txtfile holding it, or atableanswer read bytfl_ai_parse().- dir
The study folder to write into.
- overwrite
Write over files already there?
Details
The answer to a table prompt (tfl_ai_prompt()) – one block, its
outputs: the report files of a batch – is written too: give the
answer read by tfl_ai_parse() (or its text). Each report becomes
spec/outputs/<id>.yml, written as tfl_write_output() writes one,
and its assumptions join spec/_assumptions.yml (the items of these
reports replaced, the others kept), so the batches of a study add up in
one folder. Check the answer first (tfl_ai_check()): a report that
could not be read is not written.
Only spec files are written: study.yml, and .yml files under spec/
(spec/data.yml, spec/toc.yml, spec/defaults.yml,
spec/patterns/<name>.yml, spec/outputs/<id>.yml,
spec/_assumptions.yml). A block under any other heading, a path that
leaves the folder, or a file twice is an error that names it, and nothing
is written. Each file is checked as YAML before any is written.
Examples
answer <- c("### spec/outputs/T-1.yml", "", "```yaml", "id: T-1", "kind: table",
"content:", " - table_plan: {cols: TRT01A}", "```")
d <- tempfile("study-")
tfl_ai_unpack(answer, d)
tfl_read_output(file.path(d, "spec", "outputs", "T-1.yml"))
#> <tfl_output> T-1 (table)
#> extends: defaults
#> content:
#> - table_plan(cols)