2013-02-19 90 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的用戶是一點點技術爲導向的,所以他們可能不會被它嚇得大多數普通用戶。