Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Markdown YAML "Scanner error: mapping values..."

I have noticed this issue when knitting all file types (html, pdf, word). To make sure there's not an issue specific to my program, I went ahead and ran the default .rmd file you get when you create a new markdown. In each case, it does knit correctly, but I always see this at the end. I have searched online and here but cannot seem to find an explanation

Error in yaml::yaml.load(string, ...) : 
  Scanner error: mapping values are not allowed in this context at line 6, column 19
Error in yaml::yaml.load(string, ...) : 
  Scanner error: mapping values are not allowed in this context at line 6, column 19
Error in yaml::yaml.load(string, ...) : 
  Scanner error: mapping values are not allowed in this context at line 4, column 22

Here is my default YAML

---
title: "Untitled"
author: "Scott Jackson"
date: "April 20, 2017"
output: word_document
---

Line 4, column 22 is the space between the 7 and " I'm not sure where Line 6, column 19 is, but that line is the dashes at the bottom

Any ideas?

Thank you.

like image 778
Scott Jackson Avatar asked Apr 20 '17 18:04

Scott Jackson


3 Answers

I realize this question has gone unanswered for awhile, but maybe someone can still benefit. I had the same error message and I realized I had an extra header command in my yaml. I can't reproduce your exact error, but I get the same message with different line/column references with:

---
title: "Untitled"
author: "Scott Jackson"
date: "April 20, 2017"
output: output: word_document
---

Error in yaml::yaml.load(string, ...) : 
  Scanner error: mapping values are not allowed in this context at line 4, column 15
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load_utf8 -> <Anonymous>
Execution halted

Line 4 column 15 seems to refer to the second colon after the second "output".

like image 167
user29609 Avatar answered Oct 23 '22 19:10

user29609


I get this error when trying to add a table of contents to the YAML:

title: "STAC2020 Data Analysis"
date: "July 16, 2020"
output: html_notebook:
  toc: true

However, if I put html_notebook: on to a separate line then I don't get the error:

title: "STAC2020 Data Analysis"
date: "July 16, 2020"
output:
  html_notebook:
    toc: true

I do not know why this formatting makes a difference, but it allowed my document to knit and with a table of contents.

like image 45
Tim Ewers Avatar answered Oct 23 '22 19:10

Tim Ewers


I received this error when there was an indentation in the wrong place:

For example, the indentation before header-includes as seen in the example code below caused the error

---
title: "This is a title"
author: "Author Name"
   header-includes:
.
.
.
---

When you remove the indentation, the following code below did not produce the error:

---
title: "This is a title"
author: "Author Name"
header-includes:
.
.
.
---
like image 6
Kimberly Brink Avatar answered Oct 23 '22 20:10

Kimberly Brink