edit_toml {strata}R Documentation

Edit a toml file by providing a dataframe replacement

Description

Users can use edit_toml() to edit a toml file (should they opt not to use a text editor) by providing a dataframe of the desired contents. The function will check the dataframe for validity and then rewrite the toml file using the dataframe as a blueprint.

Usage

edit_toml(original_toml_path, new_toml_dataframe)

Arguments

original_toml_path

Path to the original toml file.

new_toml_dataframe

Dataframe of the new toml file contents with the following columns: type, name, order, skip_if_fail, created.

Value

invisible original toml file path to toml file

new_toml_dataframe

edit_toml() will check the dataframe for the following columns:

Unexpected columns will be dropped, and edit_toml() will warn the user. If there are any missing columns, edit_toml() will return an error, stop and inform the user what is missing.

If there are duplicates in the order than strata will rewrite the order using its best guess.

usage

Users using this function will likely want to combine some of the other helpers in strata. This may looks something like this:

Examples

tmp <- fs::dir_create(fs::file_temp())
strata::build_quick_strata_project(tmp, 2, 3)
original_toml_path <- survey_tomls(tmp)[[1]]
original_toml <- view_toml(original_toml_path)
original_toml
new_toml <- original_toml |>
  dplyr::mutate(
    created = as.Date("2021-01-01")
  )
new_toml_path <- edit_toml(original_toml_path, new_toml)
view_toml(new_toml_path)
fs::dir_delete(tmp)

[Package strata version 1.4.5 Index]