Rstudio/R can't find path for sh

Having a critical issue installing packages in R (I'm on Mac OS). I tried installing a package (below) using Rstudio:

> install.packages("igraph")
Installing package into ‘/usr/local/lib/R/3.6/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/igraph_1.2.4.1.tar.gz'
Content type 'application/x-gzip' length 2704004 bytes (2.6 MB)
==================================================
downloaded 2.6 MB

* installing *source* package ‘igraph’ ...
** package ‘igraph’ successfully unpacked and MD5 sums checked
** using staged installation
./configure: line 473: sed: command not found
./configure: line 472: expr: command not found
./configure: line 473: sed: command not found
./configure: line 487: sed: command not found
: error: cannot create .lineno; rerun with a POSIX shell
ERROR: configuration failed for package ‘igraph’
* removing ‘/usr/local/lib/R/3.6/site-library/igraph’
sh: rm: command not found
Warning in install.packages :
  installation of package ‘igraph’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/ll/jmydhb6n7jqg5rv_c58jxkkh0000gn/T/Rtmpi1rAL3/downloaded_packages’

I then tried it in R console:

> install.packages("igraph")
Installing package into ‘/usr/local/lib/R/3.6/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.ma.imperial.ac.uk/src/contrib/igraph_1.2.4.1.tar.gz'
Content type 'application/x-gzip' length 2704004 bytes (2.6 MB)
==================================================
downloaded 2.6 MB

/usr/local/Cellar/r/3.6.1/lib/R/bin/R: line 143: exec: sh: not found

The downloaded source packages are in
	‘/private/var/folders/ll/jmydhb6n7jqg5rv_c58jxkkh0000gn/T/Rtmpq31bYd/downloaded_packages’
Warning messages:
1: In system2(cmd0, args, env = env, stdout = outfile, stderr = outfile,  :
  error in running command
2: In install.packages("igraph") :
  installation of package ‘igraph’ had non-zero exit status

Below are the details I can get on my various PATHs:

From Rstudio:

Sys.getenv("PATH")
[1] "/Users/gordon.beattie/.virtualenvs/r-reticulate/bin:/Users/gordon.beattie/.virtualenvs/r-reticulate/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/gordon.beattie/Downloads/R_packages/gliph-master/gliph/bin"

From R console

> Sys.getenv("PATH")
[1] "/usr/local/bin"

From .Renviron

R_LIBS=~/R/library
PAGER=/usr/local/bin/less
PATH=/Users/gordon.beattie/Downloads/R_packages/gliph-master/gliph/bin
PATH=/usr/local/bin
PATH=/usr/local/bin
PATH=/usr/bin
PATH=/bin
PATH=/usr/sbin
PATH=/sbin
PATH=/Users/gordon.beattie/.virtualenvs/r-reticulate/bin
PATH=/Users/gordon.beattie/.virtualenvs/r-reticulate/bin
PATH=/usr/bin:/bin:/usr/sbin
PATH=/sbin
PATH=/usr/local/bin

My system PATH

echo $PATH
/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Additional info:

echo $0
-bash

echo $SHELL
/bin/bash

which sh
/bin/sh

Since you're on a Mac, you shouldn't need external requirements (see the igraph docs requirements section here).

Did you by chance install R using homebrew? If so, take a look here
https://rstats.wtf/set-up-an-r-dev-environment.html#what-about-homebrew

Summary of problem:

Unfortunately, when R is installed in this way it is not compatible with the CRAN package binaries, which means you must build and install all packages from source.
Don't worry, they explain the fix there as well.

To isolate some variables here, does this work for you in R but not in RStudio? (see FAQ below for disambiguation)

Thank you for the input!

I didn't use homebrew no.

I have got around my issue by reinstalling R, now packages seem to be installing just fine.

Good to hear. That's strange, I wonder why you got:

/usr/local/Cellar/r/3.6.1/lib/R/bin/R: line 143: exec: sh: not found

the first time around. :thinking: Totally possible that's normal. Anyhow, glad to hear all's working again.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.