3

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.

Ken Williams
  • 22,756
  • 10
  • 85
  • 147

3 Answers3

1

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:~$ 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Hmm - it looks like my `/usr/local/Cellar/r/3.2.2_1/R.framework/Versions/3.2/Resources/etc/Renviron` file (I'm on a Mac, R is installed using Homebrew) contains `R_TEXI2DVICMD=${R_TEXI2DVICMD-${TEXI2DVI-'/usr/local/opt/texinfo/bin/texi2dvi'}}`. – Ken Williams Nov 30 '15 at 21:17
  • Yes these things get diagnosed "and written down" during configuration and build. You could just edit that file (and the loose the change on thenext upgrade). Setting a (user-local or system-wide) environment variable may better. – Dirk Eddelbuettel Nov 30 '15 at 21:20
  • I don't think I have an opportunity to set `R_TEXI2DVICMD` or `TEXI2DVI` before R is launched, unless I set it in `/etc/launchd.conf` or something (http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x) – Ken Williams Nov 30 '15 at 21:22
  • Why? Also see my edit: R itself gives you two files in its `etc/` and your `$HOME`. – Dirk Eddelbuettel Nov 30 '15 at 21:24
  • Oh yes, forgot about `Renviron.site`, that's probably a good place to set it. – Ken Williams Nov 30 '15 at 21:24
  • What are the 2 files in `$HOME`? Neither `.Rprofile` nor `.Renviron` seems to have any effect. – Ken Williams Nov 30 '15 at 21:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96600/discussion-between-ken-williams-and-dirk-eddelbuettel). – Ken Williams Nov 30 '15 at 21:30
  • I realize I can edit my `.Rprofile` to affect an R session. What I claim (see my original question) is that it doesn't affect `R CMD Rd2pdf` in any helpful way. I'll edit my question to make this more explicit. – Ken Williams Nov 30 '15 at 22:15
  • It will affect _new_ sessions and as such will effect the _next time_ you lauch `R CMD foo` for various `foo` subcommands supported by R. It will affect the _current_ section because these files are read at startup. – Dirk Eddelbuettel Nov 30 '15 at 22:19
  • And recall that I recommended from the start that you alter your `bash` or whatever settings. If OS X forbids that, then, well, go complain to Cupertino because this no longer is the Unix was. But you can _always_ craft your own shell script with its own settings. This thread has gotten too long, so I will now excuse myself. – Dirk Eddelbuettel Nov 30 '15 at 22:20
  • Ok, looks like `R CMD ...` is indeed skipping this so if I were you I'd just edit the main `Renviron` file which is clearly wrong for your system. Your mileage may vary. – Dirk Eddelbuettel Nov 30 '15 at 22:23
  • And as for your edit above, **I never said that `Sys.setenv("somekey"="somevalue")` would work**. You have to set these **before** R starts to affect the **current** process from which you run subcommands. – Dirk Eddelbuettel Nov 30 '15 at 22:25
  • Thanks for the help - I'd like to condense this info into only the relevant parts for the question, so that I have something to point co-workers & other Homebrew users at. I'm happy to do that, but if you'd like to instead, please feel free. – Ken Williams Dec 01 '15 at 15:03
  • It's a bug in homebrew and the resulting R installation. No more, no less. Have it fixed there are you're good. – Dirk Eddelbuettel Dec 01 '15 at 15:54
  • Ya great. In the meantime I'll write up something here to work around it. – Ken Williams Dec 01 '15 at 15:56
  • I'm having a similar issue, `Running 'texi2dvi' on 'Rd2.tex' failed.` and `/usr/local/bin/texi2dvi: makeindex failed`. `/usr/local/bin/texi2dvi: line 281: makeindex: command not found`. I'm getting this during the `R CMD check`, but I could be able to reproduce the case by doing: `R CMD Rd2pdf package_name --no-clean`. My current `$PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/bin`. Thanks in advance! – Pablo Casas Jun 15 '20 at 02:53
1

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.

wab
  • 797
  • 6
  • 19
0

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.

Ken Williams
  • 22,756
  • 10
  • 85
  • 147