Skip to contents

The CppJson class wraps an external pointer to C++ JSON object for a seamless R serialization interface. This function group provides several utilities for creating CppJson objects: from scratch (i.e. initializing an empty JSON object), from a JSON file, or from a string that parses to valid JSON.

createCppJson creates a new (empty) CppJson object. createCppJsonFile creates and populates a CppJson object from data in a JSON file. createCppJsonString creates and populates a CppJson object from a JSON string.

These functions are intended for advanced use cases in which users require detailed control of sampling algorithms and data structures. Minimal input validation and error checks are performed – users are responsible for providing the correct inputs. For tutorials on the "proper" usage of the stochtree's advanced workflow, we provide several vignettes at https://stochtree.ai/

Usage

createCppJson()

createCppJsonFile(json_filename)

createCppJsonString(json_string)

Arguments

json_filename

Name of JSON file to read. Must end in .json.

json_string

JSON string

Value

Each of the functions in this group returns a CppJson object.

Examples

example_vec <- runif(10)
example_json <- createCppJson()
example_json$add_vector("myvec", example_vec)
tmpjson <- tempfile(fileext = ".json")
example_json$save_file(file.path(tmpjson))
example_json_roundtrip <- createCppJsonFile(file.path(tmpjson))
unlink(tmpjson)
example_json_string <- example_json$return_json_string()
example_json_roundtrip <- createCppJsonString(example_json_string)