Serialises a theory object to disk. The file extension sets the format:
JSON for .json and YAML otherwise. Files are UTF-8 with LF line
endings.
Details
Each number is written with the fewest significant digits, up to 17, that
read back as the same double in both formats, so the file holds the theory's
numbers exactly. A date or a date-time is written as text, such as
"2026-11-23". Logicals are written as
true and false, and a missing value (NA) is written as
null, which reads back as NULL in R and None in Python. Every
field the schema types as an array of strings (derives_from,
diagnostic_vs, protects, measurement,
boundary_conditions, key_constructs) is written as an array,
even when the theory holds it as a single string. A theory that validates
against the package's own schema therefore still validates once written, and
it reads back the same in R and in Python. A single string held in such a
field reads back as a one-element array, which tf_content_hash() reads as
it reads the string, so a hash recorded in version$content_hash still
matches the theory.