1

I'm trying to create the following .YAML file:

summary:
  title: "Table tabs"
  link: ~
  blocks: []
  nested: nav-pills
  nested_names: yes

(note there are no quotes around the tilde, square brackets or yes).

I write the code to create it in R:

tabs <- list(
        summary = 
            list(
                title = "Table tabs", 
                link = "~", 
                blocks = "[]", 
                nested = "nav-pills",
                nested_names = "yes"
                )
            )

write(yaml::as.yaml(tabs), file = "myfile.yaml"

But when I write it out to .YAML, it looks like this:

summary:
  title: Table tabs
  link: '~'
  blocks: '[]'
  nested: nav-pills
  nested_names: 'yes'

i.e. There are quotations around the tilde, square brackets and yes.

Why does this happen, and what can I do to prevent it?

icedcoffee
  • 935
  • 1
  • 6
  • 18

2 Answers2

1

The information is already provided in stackoverflow: I try to point you through the given answers:

More general considerations using quotes in yaml are discussed sufficiently in the question "YAML: Do I need quotes for strings in YAML?"

Here the difference of ' and "in yaml is discussed: "What is the difference between a single quote and double quote in Yaml header for r Markdown?"

Specifically the tilde sign is discussed here: "What is the purpose of tilde character ~ in YAML?"

To summarise,

The tilde is one of the ways the null value can be written. Most parsers also accept an empty value for null, and of course null, Null and NULL

mhovd
  • 3,724
  • 2
  • 21
  • 47
TarJae
  • 72,363
  • 6
  • 19
  • 66
1

Based on the answer from TarJae, the solution is as follows:

tabs <- list(
        summary = 
            list(
                title = "Table tabs", 
                link = NULL, 
                blocks = list(), 
                nested = "nav-pills",
                nested_names = TRUE
                )
            )
icedcoffee
  • 935
  • 1
  • 6
  • 18