Takes a named R list and writes it to a YAML file.
Value
This function does not return a value. It prints a message indicating that the file was successfully written.
Details
The function converts the R list to YAML text using yaml::as.yaml() and then writes it out either to a
plain text file or to a gzipped file if compress = TRUE. The gzipped file is created using a connection
opened with gzfile().
Examples
if (FALSE) { # \dontrun{
sample_data <- list(
group1 = list(
value1 = rnorm(100),
value2 = runif(100)
),
group2 = list(
message = "Hello, MOSAIC!",
timestamp = Sys.time()
)
)
# Write to a plain YAML file.
output_file <- "output.yaml"
write_list_to_yaml(data_list = sample_data, file_path = output_file, compress = FALSE)
# Write to a gzipped YAML file.
output_file_gz <- "output.yaml" # Note: the function will change this to output.yaml.gz
write_list_to_yaml(data_list = sample_data, file_path = output_file_gz, compress = TRUE)
# Load the plain YAML file to inspect its contents.
yaml_data <- yaml::read_yaml(output_file)
print(yaml_data)
} # }
