更新:
在尝试了对此问题的评论中详述的各种事情后,我的问题已经演变。正如@apple16 所建议的那样,之前在这个问题中描述的问题确实可能是由于错误的JSON 造成的,或者与"$PATH"
@RandyLai 讨论的那样与我的配置有关。
我可能已经确定了根本问题:字符编码。使用我在 Sublime Text 中的构建变体和我的.Rmd
文档的 YAML 前端中的变音符号(我在这里提出原始问题时一直在这样做)会导致与最初描述的错误不同的错误,我似乎不再得到:
Error en yaml::yaml.load(front_matter)
有趣的是,这个错误不会在 RStudio 或终端(或从 shell 脚本)中使用相同的 YAML 引发,在这些地方一切都完美呈现。当我从 YAML 中删除变音符号时,ST 中没有错误;但是,如果我将变音符号放在主文档中,它们会像NA
在生成的 HTML 中一样呈现。这种类似于之前发生的事情,我在下面描述为“古怪错误”的 HTML 输出。
在对这个问题的评论中,我尝试对我的事情做各种事情"$PATH"
,现在就像@RandyLai 一样,似乎没有必要;我特别指的是添加路径 to pandoc
:/etc/launchd.config
在恢复默认路径后/usr/bin:/bin:/usr/sbin:/sbin
,一切都在 ST 中工作,正如我现在描述的那样,无论我在SublimeKnitr-knitr
's.sublime-build
还是在R Box-R Markdown
's中使用我的构建变体.sublime-build
。
这是我的语言环境信息,以防有用:
Mi-Mac:~ LeGastronome$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
我试图找出 Sublime Text 如何执行其.sublime-build
文件。
在我的 Mac (v10.9.3) 上的 Sublime Text 3 中,我为SublimeKnitrknitr-Markdown
和R Box的R Markdown
语法创建了一个自定义构建变体;这是我.sublime-build
的前者文件,它具有功能齐全的原始/默认构建,然后是我的错误变体:
{
"selector": "text.html.markdown.knitr",
"working_dir": "${project_path:${folder}}",
"cmd": [ "Rscript -e \"library(knitr); knit('$file', output='$file_path/$file_base_name.md')\"" ],
"shell": true,
"variants":
[
{
"name": "Render",
"working_dir": "$file_path",
"shell_cmd": "Rscript -e \"rmarkdown::render(input = '$file')\""
}
]
}
这是我.sublime-build
的 for R Box 的 R Markdown,它与 SublimeKnitr 的 knitr-Markdown 构建非常相似:
{
"selector": "text.html.rmarkdown",
"working_dir": "${project_path:${folder}}",
"cmd": [ "Rscript -e \"library(knitr); knit('$file', output='$file_path/$file_base_name.md')\"" ],
"shell": true,
"variants":
[
{
"name": "Render",
"working_dir": "$file_path",
"shell_cmd": "Rscript -e \"rmarkdown::render(input = '$file')\""
}
]
}
在我的自定义构建变体中,我尝试使用这对键cmd
和shell
,以及shell_cmd
上面代码中引用的,我认为这是 ST3 的新功能。无论如何,在终端中,两者都会做我运行时都不会发生的不良事情:
Rscript -e "rmarkdown::render(input = 'path/to/file.Rmd')"
也不是当我运行时,在 RStudio 中:
rmarkdown::render(input = 'path/to/file.Rmd')
使用 SublimeKnitr 的构建与使用 R Box 的构建一样,我得到了相同的结果。我得到的输出如下:
与映射:
"cmd": [ "Rscript -e \"rmarkdown::render(input = '$file')\"" ], "shell": true
我得到:
Error: pandoc version 1.12.3 or higher is required and was not found. Ejecuci'on interrumpida [Finished in 0.4s with exit code 1] [cmd: ['Rscript -e "rmarkdown::render(input = \'/path/to/file.Rmd\')"']] [dir: /path/to/pertinent/directory] [path: /usr/bin:/bin:/usr/sbin:/sbin]
请注意,我确实已经
pandoc
安装并完全运行,例如:Mi-Mac:~ LeGastronome$ pandoc --version pandoc 1.12.4.2 Compiled with texmath 0.6.6.1, highlighting-kate 0.5.8.1. Syntax highlighting is supported for the following languages: actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog, clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d, diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang, fortran, fsharp, gcc, gnuassembler, go, haskell, haxe, html, ini, isocpp, java, javadoc, javascript, json, jsp, julia, latex, lex, literatecurry, literatehaskell, lua, makefile, mandoc, markdown, matlab, maxima, metafont, mips, modelines, modula2, modula3, monobasic, nasm, noweb, objectivec, objectivecpp, ocaml, octave, pascal, perl, php, pike, postscript, prolog, python, r, relaxngcompact, restructuredtext, rhtml, roff, ruby, rust, scala, scheme, sci, sed, sgml, sql, sqlmysql, sqlpostgresql, tcl, texinfo, verilog, vhdl, xml, xorg, xslt, xul, yacc, yaml Default user data directory: /Users/LeGastronome/.pandoc Copyright (C) 2006-2014 John MacFarlane Web: http://johnmacfarlane.net/pandoc This is free software; see the source for copying conditions. There is no warranty, not even for merchantability or fitness for a particular purpose.
与映射:
"shell_cmd": "Rscript -e \"rmarkdown::render(input = '$file')\""
我得到了所需的文档类型 HTML,但 HTML 非常错误,并且与从终端和 RStudio 运行上述代码时得到的不同;此外,仅在 Sublime Text 中,我收到以下警告:
pandoc: YAML header is not an object "source" (line 1, column 1)
请注意,如果像上面引用的原始构建配置一样,我使用括号“ [ ”,如下所示:
"shell_cmd": [ "Rscript -e \"rmarkdown::render(input = '$file')\"" ]
当我尝试运行构建变体时,除了保存我的文件之外,Sublime 不构建也不做任何事情。
我的问题似乎是特定于用户的,因此我正在寻找有关如何.sublime-build
执行文件的更精确信息。我从一些非官方文档中了解到,默认情况下会运行一些 Python;但是,如上所述,当我从终端运行与我的构建变体中包含的相同代码时,怎么可能呢,即:
Rscript -e "rmarkdown::render(input = 'path/to/file.Rmd')"
我从 Sublime Text 得到了如此不同的结果?谢谢你的帮助。