更新 :
在尝试了对此问题的评论中详述的各种事情后,我的问题有所发展。前面在这个问题中描述的问题确实可能是由于错误的 JSON,如@apple16 所建议的,或者与我的 "$PATH"
有关。配置,如与@RandyLai 所述。
我可能已经确定了潜在的问题:字符编码。在我的 .Rmd
的 YAML 前端使用我在 Sublime Text 中的构建变体和变音符号文档(我在这里提出原始问题时一直在做)导致与最初描述的错误不同的错误,我似乎不再得到:
Error en yaml::yaml.load(front_matter)
有趣的是,在 RStudio 或终端(或从 shell 脚本)中使用相同的 YAML 不会抛出此错误,在那里一切都完美呈现。当我从 YAML 中删除变音符号时,我在 ST 中没有错误;但是,如果我将变音符号放在主文档中,它们将呈现为
NA
在生成的 HTML 中。这种类似于之前发生的事情,我在下面将其描述为“奇怪的错误”HTML 输出。在对这个问题的评论中,我试图对我的
"$PATH"
做各种事情。现在,就像@RandyLai 那样,似乎没有必要;我特别指的是将路径添加到 pandoc
至 /etc/launchd.config
: 恢复默认路径后 /usr/bin:/bin:/usr/sbin:/sbin
,正如我现在描述的那样,一切都在 ST 中工作,无论我是否在 SublimeKnitr-knitr
中使用我的构建变体|的 .sublime-build
或在 R Box-R Markdown
的 .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 中,我为 SublimeKnitr 创建了一个自定义构建变体的
knitr-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
对于 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')\""
}
]
}
在我的自定义构建变体中,我尝试使用这对 key
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
的更准确信息。文件被执行。我从 some unofficial documentation 了解到默认情况下会运行一些 Python;但是,如上所述,当我从终端运行与我的构建变体中包含的代码相同的代码时,怎么可能,即:Rscript -e "rmarkdown::render(input = 'path/to/file.Rmd')"
我从 Sublime Text 得到了如此不同的结果?谢谢你的帮助。
最佳答案
你的系统好像不是英文的。当您在终端中运行 R 时,由于“LC_CTYPE”是 utf-8,R 会将文档读取为 UTF-8 文档。但是,如果在 Sublime 中启动命令,“LC_CTYPE”为空,因此 R 不知道使用什么编码。
有几种解决方案。
关于r - `.sublime-build` 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24235175/