Skip to contents

Thin wrapper around to_yaml() calling validate() before converting to YAML and creating the file, ensuring that the saved configuration is valid.

Usage

write_config(x, path = NULL)

Arguments

x

S7schema object to write.

path

character(1) path to the file to write to. Default NULL uses x@file for S7schema() objects.

Value

Invisible x (the input S7schema object). Called for side effect of writing the file.

Examples

# Read configuration file:
x <- S7schema(
  file = system.file("examples/config.yml", package = "S7schema"),
  schema = system.file("examples/schema.json", package = "S7schema")
)

print(x)
#> <S7schema::S7schema> List of 1
#>  $ my_config_var: int 1
#>  @ schema   : chr "/home/runner/work/_temp/Library/S7schema/examples/schema.json"
#>  @ validator: <S7schema::validator>
#>  .. @ context:List of 6
#>  .. .. $ context :<pointer: 0x64208fcd7180> 
#>  .. .. $ validate:function (code_string)  
#>  .. .. $ source  :function (file = NULL, code = NULL)  
#>  .. .. $ call    :function (function_name, ...)  
#>  .. .. $ get     :function (var_name)  
#>  .. .. $ assign  :function (var_name, value)  
#>  .. .. - attr(*, "class")= chr "JSContext"
#>  @ file     : chr "/home/runner/work/_temp/Library/S7schema/examples/config.yml"

# Edit content
x$my_config_var <- 2

# Save new file
write_config(
  x = x,
  path = tempfile(fileext = ".yml")
)