【问题标题】:Set 'texi2dvi' for 'R CMD Rd2pdf'为“R CMD Rd2pdf”设置“texi2dvi”
【发布时间】:2016-04-15 19:12:41
【问题描述】:

我的texi2dvi 显然在R CMD Rd2pdf 没想到的地方。我的是/usr/local/bin/texi2dvi,正在/usr/local/opt/texinfo/bin/texi2dvi寻找它:

[KenMacBook:~/git] % \R CMD Rd2pdf missing
Hmm ... looks like a package
Converting Rd files to LaTeX 
Creating pdf output from LaTeX ...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
  Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
  Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:

Error in running tools::texi2pdf()

我可以通过运行R_TEXI2DVICMD=/usr/local/bin/texi2dvi R CMD Rd2pdf 来解决这个问题,然后正确构建文档。

我想将该设置放在我的.Rprofile 中,这样 RStudio(不会读取我的.zshrc)和其他随机 R 会话之类的东西就会看到该设置。但以下两项似乎对我的.Rprofile 没有任何影响:

Sys.setenv(R_TEXI2DVICMD='/usr/local/bin/texi2dvi')
options(texi2dvi='/usr/local/bin/texi2dvi')

我猜.Rprofile 不会被R CMD 命令读取,对吗?有合适的地方放置我的设置吗?

更新:

由于 Dirk 怀疑我对 .RProfile 影响 R CMD Rd2pdf 的怀疑 :-),这是我的证据:

[KenMacBook:~/git] % tail -n2 ~/.Rprofile
Sys.setenv(TEXI2DVI='/no/where')
cat("End of RProfile\n")

[KenMacBook:~/git] % Rscript -e '2+2'    
End of RProfile
[1] 4

[KenMacBook:~/git] % R CMD Rd2pdf missing
Hmm ... looks like a package
Converting Rd files to LaTeX 
Creating pdf output from LaTeX ...
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
  Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:

Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
  Running 'texi2dvi' on 'Rd2.tex' failed.
Messages:
sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
Output:

Error in running tools::texi2pdf()

请注意,文件的设置在正常的 R 会话中受到尊重,但设置 TEXI2DVI 在此处无效。

【问题讨论】:

    标签: r documentation packages texinfo


    【解决方案1】:

    这似乎是错误的,因为 /usr/local/bin/texi2dvi 应该在 $PATH 中。 我有

    edd@max:~$ grep texi2dvi /etc/R/Renviron
    ## used for options("texi2dvi")
    R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/bin/texi2dvi'}}
    edd@max:~$ 
    

    请注意,如果您想设置 TEXI2DVI 环境变量,您可能必须在启动 R 之前启动 -- 想想 ~/.bash_profile

    这是一个示例显式设置TEXI2DVI

    edd@max:/tmp$ TEXI2DVI=/no/where R CMD Rd2pdf Rcpp-package.Rd 
    Converting Rd files to LaTeX ...
      Rcpp-package.Rd
    Creating pdf output from LaTeX ...
    Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
      Running 'texi2dvi' on 'Rd2.tex' failed.
    Messages:
    sh: 1: /no/where: not found
    Output:
    
    Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
      Running 'texi2dvi' on 'Rd2.tex' failed.
    Messages:
    sh: 1: /no/where: not found
    Output:
    
    Error in running tools::texi2pdf()
    edd@max:/tmp$ 
    

    如您所见,它受到尊重。

    编辑:另外,我们不要忘记RenvironRenviron.site,所以你有很多选择,所以设置他的。

    编辑 2: 你似乎怀疑~/.Rprofile

    edd@max:~$ tail -1 .Rprofile
    cat("End of .Rprofile\n")
    edd@max:~$ Rscript -e '2+2'
    End of .Rprofile
    [1] 4
    edd@max:~$ 
    

    【讨论】:

    • 嗯 - 它看起来像我的 /usr/local/Cellar/r/3.2.2_1/R.framework/Versions/3.2/Resources/etc/Renviron 文件(我在 Mac 上,R 是使用 Homebrew 安装的)包含 R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/opt/texinfo/bin/texi2dvi'}}
    • 是的,这些东西在配置和构建过程中得到诊断并“记录下来”。您可以只编辑该文件(并在下一次升级时松散更改)。设置(用户本地或系统范围的)环境变量可能会更好。
    • 我认为我没有机会在 R 启动之前设置 R_TEXI2DVICMDTEXI2DVI,除非我将其设置为 /etc/launchd.conf 或其他东西 (stackoverflow.com/questions/135688/…)
    • 为什么?另请参阅我的编辑:R 本身在其etc/ 和您的$HOME 中为您提供了两个文件。
    • 哦,是的,忘了Renviron.site,那可能是个设置它的好地方。
    【解决方案2】:

    遇到了同样的问题并想出了如何解决它 - 我认为这与之前安装的 macports 干扰了使用 brew 安装 R 时的路径有关(假设你在 OSX 上)。

    在终端中运行以下命令:

    defaults write com.apple.finder AppleShowAllFiles TRUE
    

    然后转到 Apple > 强制退出 > Finder > 重新启动。您现在可以看到隐藏文件。

    在您的用户目录中可能有一个名为 .profile 的文件,在此文件中我注释掉了该行(即在其前面放一个 #,如图所示)。

    #export PATH=/opt/local/bin:/opt/local/sbin:$PATH
    

    然后导航到您的 R.home() (通过在 R 中运行 R.home() 来获取)

    R.home()
    [1] "/usr/local/Cellar/r/3.2.4_1/R.framework/Resources"
    

    并在 Renviron 中修改以下行

    R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/bin/texi2dvi'}}
    

    这为我解决了问题。

    让finder恢复正常运行

    defaults write com.apple.finder AppleShowAllFiles FALSE

    在终端中重新启动它。

    希望对您有所帮助。

    【讨论】:

      【解决方案3】:

      与 Dirk 的反复讨论产生了一些解决方案,但它们都被埋没了,所以我在这里总结一下。

      诊断:etc/Renviron 包含陈旧信息。

      我的/usr/local/Cellar/r/3.2.2_1/R.framework/Versions/3.2/Resources/etc/Renviron 文件(使用Homebrew 安装)包含这一行:

      R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/opt/texinfo/bin/texi2dvi'}}
      

      这是在默认位置安装MacTeX 的某个人(可能是我,可能是 Homebrew 的 R 包创建者)的残余,然后该路径在Renviron 文件中及时冻结。我的texi2dvi 现在位于/usr/local/bin/texi2dvi,因此需要以某种方式覆盖此值。

      1) $HOME/.Rprofile$HOME/.Renviron 无济于事。

      它们不会很快生效以使 R 注意到它们。 R根据启动时看到的环境设置options("texi2dvi")

      % tail -n2 ~/.Rprofile
      Sys.setenv(TEXI2DVI='/no/where')
      options(texi2dvi='/no/where/else')
      
      % cat ~/.Renviron
      TEXI2DVI=/no/where/at/all
      
      % R CMD Rd2pdf myPackageDirectory   # Still no joy
      Hmm ... looks like a package
      Converting Rd files to LaTeX 
      Creating pdf output from LaTeX ...
      Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
        Running 'texi2dvi' on 'Rd2.tex' failed.
      Messages:
      sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
      ...
      

      有关启动文件的更多信息,请参阅“Initialization at Start of an R Session”,尽管如上所示,该文档中关于覆盖R_HOME/etc/Renviron 的信息对于这种情况要么不正确要么不完整。也许应该在关于R_CHECK_ENVIRONR_BUILD_ENVIRON 的部分中对其进行修改,以包括一些关于R CMD RD2* 的内容,但我不确定这是否是怎么回事,我只知道这不是一个解决方案。

      2) $HOME/.zshrc(和朋友)不会帮忙。

      在 OS X 上,启动 GUI 应用程序时不会参考您的 shell 启动文件。您可以 use defaults write or launchctl setenv 更改 TEXI2DVI 变量,以便在 R 启动时设置它,但您还必须将它粘贴在您的 shell 启动文件中,以用于由 launchd 启动的进程,这很恶心。我也是version my dotfiles,我不喜欢在launchctl ether 中坚持这一点配置,因为我不容易记住它在那里。但是launchctl 大概是解决这个问题的一种方法。

      3) etc/Renviron.site 无济于事。

      这个令人惊讶 - 我预计它会起作用:

      % cat /usr/local/Cellar/r/3.2.2_1/R.framework/Resources/etc/Renviron.site
      R_TEXI2DVICMD=/usr/local/bin/texi2dvi
      TEXI2DVI=/usr/local/bin/texi2dvi
      
      % \R CMD Rd2pdf myPackageDirectory
      Hmm ... looks like a package
      Converting Rd files to LaTeX 
      Creating pdf output from LaTeX ...
      Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
        Running 'texi2dvi' on 'Rd2.tex' failed.
      Messages:
      sh: /usr/local/opt/texinfo/bin/texi2dvi: No such file or directory
      

      所以Renviron.site 的设置在这里没有生效。我越来越不耐烦了,所以我没有尝试诊断原因。

      3) 编辑etc/Renviron 作为最后的手段

      所以这终于奏效了:

      % grep TEXI2DVI /usr/local/Cellar/r/3.2.2_1/R.framework/Resources/etc/Renviron 
      TEXI2DVI=/usr/local/bin/texi2dvi  ## Added by Ken
      R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/opt/texinfo/bin/texi2dvi'}}
      

      我不太喜欢它,因为我下次升级 R 时会丢失这些设置。而且 R 的文档特别提到 "do not change ‘R_HOME/etc/Renviron’ itself"。但至少它有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-09
        • 1970-01-01
        • 2014-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多