RMarkdown error in YAML

2019-03-24 04:49发布

问题:

I watched a great webinar by RStudio the other day about RMarkdown. After the webinar they posted the code used in the demonstrations online and I wanted to check out one example. I took their code, put it in my RStudio (which says it's fully up-to-date, v0.98.978), installed or updated all the necessary packages and hit "Run Document"

I receive an error which I do not understand and for which Google has been very unhelpful. What is this mysterious <document start> and how do I include it? I assumed all necessary components would be included given the source of the code.

Error in yaml::yaml.load(front_matter) : 
  Parser error: did not find expected <document start> at line 2, column 1
Calls: <Anonymous> -> parse_yaml_front_matter -> <Anonymous> -> .Call
Execution halted

回答1:

The issue came from copying the code from the browser to Rstudio.

The original header information was:

---
title: "Linked brushing"
output: html_document
runtime: shiny
---

the pasted text was:

---
  title: "Linked brushing"
output: html_document
runtime: shiny
---

The missing <document start> was an unequal amount of white space before each element of the header. This can be fixed by adding white space to the 'output' and 'runtime' lines or by removing the white space of the 'title' line.