我在编织所有文件类型时注意到了这个问题(html,pdf,word(。为了确保没有针对我的程序的问题,我继续运行默认的.RMD文件,您可以在创建新的标记时获得。在每种情况下,它的编织都正确,但是我总是在最后看到它。我已经在网上搜索了,但似乎找不到解释
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
这是我的默认yaml
---
title: "Untitled"
author: "Scott Jackson"
date: "April 20, 2017"
output: word_document
---
第4行,第22列是7和7之间的空间我不确定第6行第19行在哪里,但是那条线是底部的破折号
有什么想法?
谢谢。
我在尝试将目录添加到yaml时会遇到此错误:
title: "STAC2020 Data Analysis"
date: "July 16, 2020"
output: html_notebook:
toc: true
但是,如果我将 html_notebook:
放在单独的行上,那么我不会得到错误:
title: "STAC2020 Data Analysis"
date: "July 16, 2020"
output:
html_notebook:
toc: true
我不知道为什么这种格式会有所作为,但它允许我的文档编织并使用目录。
我意识到这个问题已经有一段时间没有得到答复,但也许有人可以从中受益。我有相同的错误消息,我意识到我的yaml中有一个额外的标头命令。我无法重现您的确切错误,但是我通过不同的行/列参考获得了相同的消息:
---
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
第4列第15列似乎是指第二个"输出"之后的第二个结肠。
我在错误的位置有凹痕时收到了此错误:
例如,在下面的示例代码中看到的header-includes
之前的凹痕引起了错误
---
title: "This is a title"
author: "Author Name"
header-includes:
.
.
.
---
删除缩进时,以下代码不会产生错误:
---
title: "This is a title"
author: "Author Name"
header-includes:
.
.
.
---
与蒂姆·埃沃斯(Tim Ewers(类似,当我在yaml中添加toc时,我也遇到了这个错误:
title: "My title"
date: "April 1, 2020"
output:
pdf_document: default
toc: true
html_document: paged
但是,我发现的解决方案是删除"默认值",这使我可以编织文档而不会出错:
title: "My title"
date: "April 1, 2020"
output:
pdf_document:
toc: true
html_document: paged
我知道这是一个5年的问题,但是我遇到了同样的错误,因为我缺少结肠
---
title: ''
output:
pdf_document
includes:
before_body: before_body.tex
---
应该是
---
title: ''
output:
pdf_document:
includes:
before_body: before_body.tex
---
虽然这并不能严格回答给出的示例,但我希望它将帮助未来的错误消息。
我想这个错误在您的内容上而不是yaml块上发生。因为没有额外的内容显示,所以我将举一个最小的例子。
> library(yaml)
> library(magrittr)
> "
+ ---
+ title: 'This is a title'
+ output: github_document
+ ---
+
+ some content
+ " %>%
+ yaml.load()
$title
[1] "This is a title"
$output
[1] "github_document"
它运行良好。这是另一个例子。
> "
+ ---
+ title: 'This is a title'
+ output: github_document
+ ---
+
+ some content
+ some content: some content
+ " %>%
+ yaml.load()
Error in yaml.load(.) :
Scanner error: mapping values are not allowed in this context at line 8, column 13
错误发生在第8行。因为在YAML块中没有键值对。 yaml.load
对我来说还不够聪明。对我的时间解决方案是提取第二个---
上方的所有线。
> text <- "
+ ---
+ title: 'This is a title'
+ output: github_document
+ ---
+
+ some content
+ some content: some content
+ "
> library(xfun)
> read_lines(text,n_max = 5) %>%
+ yaml.load()
$title
[1] "This is a title"
$output
[1] "github_document"
我也有类似的问题,并在 yaml 和 rticles 帮助页面中提出了请求:
- https://github.com/viking/r-yaml/issues/92
- https://github.com/rstudio/rticles/issues/363