2013-02-19 91 views
1

我问一个相关的问题:从回答,直到我在所有三个系统测试自己的解决方案check if a program is installedR不承认Pandoc Linux Mint的

,但我克制。我可以得到pandoc于从R内工作的Windows机器上,但在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安装和路径上,但我相信我做的。从一个干净的终端会话:

> [email protected] ~ $ echo $PATH 
> /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/tyler/.cabal/bin 

[email protected] ~ $ 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. 

我怎样才能使R于Linux Mint的认识pandoc?(我是Linux新手)

+0

适用于Ubuntu 12.04。但是我在/ usr/bin /中有pandoc。 – EDi 2013-02-19 21:54:00

+2

Dito。 'system(“pandoc”)'返回'/ usr/bin/pandoc'。我认为你在那里过分复杂。这不是Windows。一旦你安装了一个二进制文件,“它就在那里”。 – 2013-02-19 21:55:28

+0

我试图通过cabal更新来使用更新版本的pandoc,见[这里](http://johnmacfarlane.net/pandoc/installing.html)。然而它在那个页面上说它把它放在'〜/ .cabal/bin'中。我想如果我把这些文件放到'usr'目录下,它会按预期工作,但我不知道哪里可以找到usr目录。然而,使用'sudo apt-get install pandoc'它现在可以在R上运行。 – 2013-02-20 00:11:14

回答

4

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

添加到您的.profile文件的底部,并删除路径modfication在你的.bashrc文件,你应该能够在R从认识pandoc

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

作为一个通用的解决方案,这个问题是你不能真正转过身去建议每个使用你的软件包的人,当他们最有可能已经使用'.bashrc'完成它时,我建议使用'Sys.which()'带有一组到Pandoc的典型路径。换句话说,也许它会为泰勒解决自己的问题,但不会为任何其他可能使用他的功能的人解决问题。 – A5C1D2H2I1M1N2O1R2T1 2013-02-20 02:29:48

+0

@Ananda问题不在于确定是否安装了pandoc,而是在RStudio中识别它已安装。如果我从temrtinal Rstudio发起承认它。如果我单击.Rproj文件打开RStudio,则无法识别安装了pandoc。关于bash的更多有经验的linux用户明白我还没有把握。 – 2013-02-20 02:35:58

+0

@AnandaMahto我同意你不能强迫用户使用.bashrc改为.profile,但是这确实解决了RStudio不能从'system'识别pandoc的问题。我认为你的解决方案可能是最好的选择,因为它更强大,所以在泰勒希望将其部署给普通观众的情况下,这是一个很好的措施。但对于我们这些只希望RStudio能够识别我们修改过的路径的人来说......这是奇迹。 – Dason 2013-02-20 02:38:55

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更改为以下内容。我已经评论过典型的小憩地点,所以你可以看到它是如何工作的。

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 
} 

在我的系统上,运行它看起来像这样。对于第一个问题,我回答“是”,然后它要求我指定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的用户是一点点技术为导向的,所以他们可能不会被它吓得大多数普通用户。