【问题标题】:Error in YAML when knitting RMarkdown document - Scanner error编织 RMarkdown 文档时出现 YAML 错误 - 扫描仪错误
【发布时间】:2019-03-07 06:08:58
【问题描述】:

我正在尝试在 RStudio 中编写 RMD 文件,但出现以下错误

yaml::yaml.load(string, ...) 中的错误:扫描仪错误:在第 31 行扫描纯标量时,第 5 列发现了一个制表符 这违反了第 34 行第 1 列的意图调用:... parse_yaml_front_matter -> yaml_load_utf8 -> 执行 停止

rmd文件头如下:

> --- 
> title: "Homework 4" 
> author: NAME OF THE AUTHOR, Fall 2018 
> date: Due Friday, September 30, 11:59pm 
> subparagraph: yes 
> output:  
> pdf_document:
>     number_sections: true header-includes:
>   - \setcounter{secnumdepth}{1}
>   - \pagenumbering{gobble}
>   - \sloppy
>   - \hypersetup{ breaklinks=true,
>       pdftitle={\@title},
>       pdfauthor={\@author},
>       colorlinks=true,
>       breaklinks=true,
>       urlcolor= blue,
>       linkcolor= blue,
>       citecolor=blue,
>       bookmarksopen=false,
>       pdftoolbar=false,
>       pdfmenubar=false
>     }
>   - \usepackage{titlesec}
>   - \renewcommand{\thesection}{\arabic{section}.}
>   - \usepackage{mathpazo}
>   - \usepackage{etoolbox}
>   - \usepackage{geometry}
>   - \usepackage{graphicx}
>   - \newcommand{\protectbracket}[1]{#1}
>   - \makeatletter
>     \protectbracket{\preto\Gin@extensions{svg,}}
>     \DeclareGraphicsRule{.svg}{pdf}{.pdf}{\noexpand\Gin@base.pdf}     \makeatother
>   - \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
>   - \usepackage[most]{tcolorbox}
>   - \definecolor{block-gray}{gray}{0.85}
>   - \newtcolorbox{darkquote}{colback=block-gray,grow to right by=-10mm,grow to left by=-10mm, boxrule=0pt,boxsep=0pt,breakable}
>   - \renewenvironment{quote}{\begin{darkquote}}{\end{darkquote}\ignorespacesafterend}
> ---

任何想法是什么原因造成的?错误指向第 31 行中的字符“n”,我不确定如何修复它。非常感谢任何帮助或建议。

我已经在 Mac 和 PC 上都安装了 RStudio 进行了尝试。

【问题讨论】:

    标签: r


    【解决方案1】:

    假设行首的 > 是复制和粘贴的剩余部分(它们肯定不应该在文件中),你有一个 YAML 文档,开头如下:

    --- 
    title: "Homework 4" 
    author: NAME OF THE AUTHOR, Fall 2018 
    date: Due Friday, September 30, 11:59pm 
    subparagraph: yes 
    output:  
    pdf_document:
        number_sections: true header-includes:
      - \setcounter{secnumdepth}{1}
    

    这是无效的,因为您不能同时将映射作为键 pdf_document 的值以及序列(另外缩进较少)。 这可能与行内冒号空间和行尾冒号的组合结合在一起,使解析器感到困惑

    您可能希望将其更改为以以下开头的内容:

    --- 
    title: "Homework 4" 
    author: NAME OF THE AUTHOR, Fall 2018 
    date: Due Friday, September 30, 11:59pm 
    subparagraph: yes 
    output:  
    pdf_document:
        number_sections: true
    header-includes:
      - \setcounter{secnumdepth}{1}
    

    【讨论】:

    • 您好,Anthon,感谢您的回答。是的,它是从 RStudio 复制和粘贴的。我在上面和这里的问题的答案中附上了屏幕截图:i.stack.imgur.com/0tx7Y.png
    • @HakimAhmadi \makeathother 第 35 行的缩进不够。
    • 我缩进了 \makeathother 并将其与其余的第 34 行对齐,但仍然是同样的错误。
    • 您是否已经删除了制表符(我可以建议您切换到不允许您意外或无意插入制表符的编辑器)。
    • 这里的制表符是什么?因为第 31 行的第 5 列是字母“n”
    猜你喜欢
    • 2017-12-07
    • 1970-01-01
    • 2019-04-23
    • 2017-09-17
    • 2018-03-18
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    相关资源
    最近更新 更多