Skip to contents

write_trials_jsonl() writes trial records to a JSON Lines file, one JSON object per trial and line. read_trials_jsonl() reads them back.

Usage

write_trials_jsonl(trials, path, append = FALSE)

Arguments

trials

A list of trial records from create_trial() or complete_trial().

path

Path of the file to write.

append

Whether to append to an existing file (default FALSE).

Value

path, invisibly.

Details

The file follows the permission rules described in TrialLog: on Unix, an existing file must be owned by the current user with mode 0600, and every existing parent directory must be owned by root or the current user. Unsafe paths are rejected rather than repaired. The directory must already exist.

Examples

trials <- list(
  create_trial("my-search", params = list(k = 2L)),
  create_trial("my-search", params = list(k = 4L))
)
path <- tempfile(fileext = ".jsonl")
write_trials_jsonl(trials, path)
readLines(path, n = 1)
#> [1] "{\"schema_version\":1,\"trial_id\":\"trial_20260930_174439_ncnyz0\",\"optimizer_name\":\"my-search\",\"params\":{\"k\":2},\"metric_summary\":[],\"cost_summary\":[],\"start_time\":\"2026-09-30T17:44:39\",\"end_time\":null,\"notes\":\"\",\"status\":\"pending\",\"trace_context\":[]}"