yml_modify: Modify YAML file headers

Description Usage Arguments Details Value Examples

Description

When the list of elements provided does not already exist in the YAML file, both yml_overwrite and yml_append behave the same way and will add it to the YAML header. However, if the element already exists, yml_overwrite will replace the values with the one provided by the function, while yml_append will add them.

Usage

1
2
3
yml_replace(file, what, output = file, encoding = getOption("encoding"))

yml_append(file, what, output = file, encoding = getOption("encoding"))

Arguments

file

the path to the file that contains the YAML header to modify.

what

a list providing the elements to add or modify in the YAML header.

output

the path to the file with the modified YAML header.

encoding

the encoding for the input file.

Details

Use NULL to remove a value from the YAML header.

Value

the path of the file containing the modified YAML header.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
pet_yaml_file <- system.file("yaml_examples", "pets.yml",
                             package="ymlplyr")
cat(readLines(con = pet_yaml_file), sep="\n")

## Add elements
example1 <- tempfile()
yml_append(pet_yaml_file,
           list(pets = list(dogs = c("Milou", "Santa Claus"),
                            cats = "Kitty",
                            rat = "Ratatouille")),
           output = example1)
cat(readLines(con = example1), sep = "\n")
unlink(example1)

## Replace elements
example2 <- tempfile()
yml_replace(pet_yaml_file,
           list(pets = list(dogs = "Milou", cats = "Kitty")),
           output = example2)
cat(readLines(con = example2), sep = "\n")
unlink(example2)

## Remove elements
example3 <- tempfile()
yml_replace(pet_yaml_file, list(pets = list(dogs = NULL)),
            output = example3)
cat(readLines(con = example3), sep = "\n")
unlink(example3)

r-education/ymlplyr documentation built on May 29, 2019, 8:23 p.m.