Running system command from R console cannot locat

2019-05-10 02:58发布

问题:

I have been having some weird issues with R (3.1.1) and RStudio (0.98.1079) and I suspect that it is due to the fact that these programs are not longer referencing the right places after I upgraded to Mac OSX 10.10.

In particular, I cannot seem to find packages that I know I have installed on my computer to run using the system command in the R console. That is, running man pdflatex in a Terminal window yields the help manual for PDFLATEX. However running system('man pdflatex') from the R console yields the error message No manual entry for pdflatex.

The issue persists even though I reinstalled R, RStudio and MacTex since I upgraded to Mac OSX 10.10. Any help would be appreciated!

回答1:

Yosemite has a bug wherein some environment variables, including PATH, appear twice in a program's environment with different values. For instance, you might notice that Sys.getenv("PATH") will show you one PATH, and system("echo $PATH") will show you an entirely different one.

I expect that most of your problems are due to this bug.

There are a few workarounds you can try immediately:

  1. You can manually forward PATH yourself. Try this:

    > system2("man", "pdflatex", env=paste0("PATH=", Sys.getenv("PATH")))
    
  2. Or, you can start RStudio from Terminal:

    $ open /Applications/RStudio.app
    

Both the R and RStudio engineers have implemented workarounds in the last few days. R (as of 3.1.2) and RStudio (as of 0.98.1087) should behave as you'd expect.



回答2:

There are a host of questions about similar problems. All of them appear to come up when you update OS X to either Yosemite or Sierra with an older version of R already installed.

The easiest solution is to completely uninstall R (note the comments about using which R !), and then to install it again.

This also solves problems such as R showing different version numbers in terminal and the GUI.



标签: r macos rstudio