R不承认Pandoc Linux Mint

时间:2013-02-19 21:48:26

标签: r pandoc mint

我问了一个相关的问题:check if a program is installed

但是在我在所有三个系统上测试自己的解决方案之前,我一直没有回答。我可以在Windows机器上从R内部使用pandoc工作但在linux上我从R终端获得每个方法的错误/响应:

1:

> system('pandoc -v')
sh: 1: pandoc: not found

2:

> myPaths <- c("pandoc", 
+              "~/.cabal/bin/pandoc", 
+              "~/Library/Haskell/bin/pandoc", 
+              "C:\\PROGRA~1\\Pandoc\\bin\\pandoc") 

> Sys.which(myPaths)
                           pandoc               ~/.cabal/bin/pandoc 
                               ""   "/home/tyler/.cabal/bin/pandoc" 
     ~/Library/Haskell/bin/pandoc C:\\PROGRA~1\\Pandoc\\bin\\pandoc 
                               ""                                "" 

3:

> Sys.which("pandoc")
pandoc 
"" 

你可能认为我没有安装pandoc并且在路上,但我相信我这样做。从一个干净的终端会议:

> tyler@trinker ~ $ echo $PATH
> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/tyler/.cabal/bin

tyler@trinker ~ $ pandoc -v
pandoc 1.10.1
Compiled with citeproc-hs 0.3.7, texmath 0.6.1.3, highlighting-kate 0.5.3.6.
Syntax highlighting is supported for the following languages:
    Actionscript, Ada, Alert, Alert_indent, 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, Gnuassembler, Go, Haskell, Haxe,
    Html, Ini, Java, Javadoc, Javascript, Json, Jsp, Julia, Latex, Lex,
    LiterateCurry, LiterateHaskell, Lua, Makefile, Mandoc, Matlab, Maxima,
    Metafont, Mips, Modula2, Modula3, Monobasic, Nasm, Noweb, Objectivec,
    Objectivecpp, Ocaml, Octave, Pascal, Perl, Php, Pike, Postscript, Prolog,
    Python, R, Relaxngcompact, Rhtml, Ruby, Scala, Scheme, Sci, Sed, Sgml, Sql,
    SqlMysql, SqlPostgresql, Tcl, Texinfo, Verilog, Vhdl, Xml, Xorg, Xslt, Xul,
    Yacc, Yaml
Copyright (C) 2006-2013 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.

如何让Linux Mint上的R识别pandoc?(我是Linux的新手)

2 个答案:

答案 0 :(得分:4)

我也遇到了这个问题。我也通过cabal安装了pandoc。如果你通过apt-get安装,应该没有问题。如果我从一个终端发射R我没有任何问题但是试图从RStudio中检测到pandoc会带来一些麻烦。原因是RStudio没有读入你的bash环境变量,所以如果修改.bashrc中的路径,RStudio将不会检测到。解决方案是通过.profile修改路径。

将其添加到.profile文件的底部并删除.bashrc文件中的路径修改,您应该能够识别R中的pandoc。

if [ -d "$HOME/.cabal/bin" ] ; then
    PATH="$PATH:$HOME/.cabal/bin"
fi

答案 1 :(得分:3)

这就是我的想法。我删除了html5函数中的所有其他内容,只是为了看看它会返回什么,并让您对我的思维过程有一个大概的了解:

首先,创建一个能找出Pandoc安装位置的函数。如果匹配多个位置(在您的情况下很可能是“pandoc”和“〜/ .cabal / bin / pandoc”,如果它正确检测到路径),它将只选择第一个选项。

wheresPandoc <- function() {
  myPaths <- c("pandoc", 
               "~/.cabal/bin/pandoc", 
               "~/Library/Haskell/bin", 
               "C:\\PROGRA~1\\Pandoc\\bin\\pandoc.exe")
  temp <- Sys.which(myPaths)
  temp <- names(temp[temp != ""])[1]
  if (is.na(temp)) stop("Pandoc not installed in one of the typical locations")
  else temp
}

单独运行该功能如下:

wheresPandoc()
# [1] "~/.cabal/bin/pandoc"

因此,您可以使用html5函数中的输出来构建system“操作”。

html5 <- function(in.file = NULL, out.file = NULL) {
  action <- paste0(wheresPandoc(), 
                   " -s -S -i -t dzslides --mathjax ", 
                   in.file, " -o ", out.file)
  action
}

html5(in.file = "this.txt", out.file = "that.html")
# [1] "~/.cabal/bin/pandoc -s -S -i -t dzslides --mathjax this.txt -o that.html"

这可能会使事情变得过于复杂,但如果您认为您的用户精通技术或者在有趣的位置安装程序的用户类型(并记住他们安装程序的位置),您可以考虑将wheresPandoc更改为类似以下内容。我已经评论了典型的cabal位置,因此您可以看到它是如何工作的。

wheresPandoc <- function() {
  myPaths <- c("pandoc", 
  #            "~/.cabal/bin/pandoc", 
               "~/Library/Haskell/bin", 
               "C:\\PROGRA~1\\Pandoc\\bin\\pandoc.exe")
  temp <- Sys.which(myPaths)
  temp <- names(temp[temp != ""])[1]
  if (is.na(temp)) {
    ans <- readline("Pandoc not installed in one of the typical locations.\n 
                    Do you know where Pandoc is installed? (y/n) ")
    if (ans == "y") temp <- readline("Enter the (unquoted) path to Pandoc: ")
    else if (ans == "n") stop("Pandoc not installed or not found.")
  } 
  temp
}

在我的系统上,运行它看起来像这样。对于第一个问题,我回答“y”,然后它要求我指定Pandoc的未引用路径,并使用它来构建system电话。

> html5(in.file = "this.txt", out.file = "that.html")
Pandoc not installed in one of the typical locations.

Do you know where Pandoc is installed? (y/n) y
Enter the (unquoted) path to Pandoc: ~/.cabal/install/pandoc
[1] "~/.cabal/install/pandoc -s -S -i -t dzslides --mathjax this.txt -o that.html"

我认识的大多数普通用户如果看到这样的问题就会关闭,但我认识的大多数R用户都有一点技术导向,所以他们可能不会太害怕。