Set 'texi2dvi' for 'R CMD Rd2pdf'

3.1k Views Asked by At

My texi2dvi is apparently in a place where R CMD Rd2pdf doesn't expect it. Mine is at /usr/local/bin/texi2dvi, and it's being looked for at /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()

I can work around this by running R_TEXI2DVICMD=/usr/local/bin/texi2dvi R CMD Rd2pdf, and then the docs are built correctly.

I'd like to put that setting in my .Rprofile so that things like RStudio (which won't read my .zshrc) and other random R sessions will see the setting. But neither of the following seems to have any effect in my .Rprofile:

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

I'm guessing .Rprofile doesn't get read by R CMD commands, is that correct? Is there an appropriate place to put my settings?

UPDATE:

Since Dirk doubts my doubting of .RProfile for affecting R CMD Rd2pdf :-), here's my evidence:

[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()

Notice that the file's settings are respected in a normal R session, but setting TEXI2DVI has no effect here.

3

There are 3 best solutions below

0
On

The back-and-forth with Dirk produced some solutions, but they're pretty buried, so I summarize them here.

Diagnosis: etc/Renviron contains stale info.

My /usr/local/Cellar/r/3.2.2_1/R.framework/Versions/3.2/Resources/etc/Renviron file (installed using Homebrew) contains this line:

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

That's a remnant of someone (possibly me, possibly Homebrew's R package creator) who installed MacTeX in the default location, and then that path got frozen in time in the Renviron file. My texi2dvi is now at /usr/local/bin/texi2dvi, so this value needs to be overridden somehow.

1) $HOME/.Rprofile and $HOME/.Renviron won't help.

They don't take effect soon enough for R to notice them. R sets options("texi2dvi") based on the environment it sees at startup,

% 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
...

See "Initialization at Start of an R Session" for more info about startup files, though as shown above, the information in that document about overriding R_HOME/etc/Renviron is either incorrect or incomplete for this situation. Perhaps it should be amended in the section about R_CHECK_ENVIRON and R_BUILD_ENVIRON to also include something about R CMD RD2*, but I'm not sure whether that's what's going on, I only know this isn't a solution.

2) $HOME/.zshrc (and friends) won't help.

On OS X, your shell startup file is not consulted when you launch GUI apps. You could use defaults write or launchctl setenv to change the TEXI2DVI variable so that it's set when R launches, but you'd also have to stick it in your shell startup file for processes not started by launchd, which is icky. I also version my dotfiles, and I don't like sticking this bit of configuration in the launchctl ether where I can't easily remember it's there. But launchctl is presumably one solution to this.

3) etc/Renviron.site won't help.

This one is surprising - I expected it to work:

% 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

So Renviron.site's settings aren't taking effect here. I'm getting impatient, so I didn't try to diagnose why.

3) Editing etc/Renviron as a last resort

So this finally works:

% 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'}}

I don't like it much, because I'll lose those settings next time I upgrade R. And R's documentation specifically says "do not change ‘R_HOME/etc/Renviron’ itself". But at least it works.

16
On

That seems wrong as /usr/local/bin/texi2dvi should be in the $PATH. I have

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

Note that if you want to set the TEXI2DVI environment variable, you probably have to do start before you start R -- think ~/.bash_profile

Here is an example explicitly setting 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$ 

As you can see, it is respected.

Edit: Also let's not forget Renviron and Renviron.site so you have plenty of choices so set his.

Edit 2: As you seem to doubt ~/.Rprofile:

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

Had the same problem and figured out how to fix it - I think it has something to do with a previous installation of macports interfering with the path when R has been installed using brew (assuming you're on OSX).

Run the following in terminal:

defaults write com.apple.finder AppleShowAllFiles TRUE

Then go Apple > Force Quit > Finder > Relaunch. You'll now be able to see hidden files.

In your user directory there may be a file named .profile, in this file I commented out the line (i.e. put a # in front of it, as shown).

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

Then navigate to your R.home() (get this by running R.home() in R)

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

And modify the following line in Renviron

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

This fixed it for me.

To put finder back to usual run

defaults write com.apple.finder AppleShowAllFiles FALSE

in the terminal and relaunch it.

Hope that helps.