Error in installing R packages- Mac OS Sonoma Intel

Dear all,

I am having issues on installing R packages in R studio. I have updated all my R and R studio and Mac version! It is Mac Sonoma with Intel. The error message i got:

sh: tar: command not found
Warning in install.packages :
error in running command
Warning in install.packages :
'tar' returned non-zero exit code 127
Error in install.packages : file ‘/var/folders/6h/6_3mc0f97ksds4kp7c783yvc0000gn/T//RtmpWr7INZ/downloaded_packages/fansi_1.0.5.tgz’ is not a macOS binary package.

I have checked with ChatGPT and tried its suggestion and it did not worked out. Does anyone have the same problem and have some solutions to suggest?

many thanks
Seher

Seems like you don't have tar on your PATH. Did you customize your PATH?

What is your R version? How did you install R?

What is the output of these commands from R?

Sys.which("tar")
Sys.getenv("PATH")

Can you try this?

Sys.setenv(TAR="internal")
install.packages("fansi")

Hi Gabor,
Thanks for your reply. R version is R 4.3.2 and i installed the way is is suggested by Posit. How to customize the PATH? That is not clear to me.

And i have tried your suggestions and here are the output:

Sys.which("tar")
tar
""
Sys.getenv("PATH")
[1] "[[ -r /usr/local/etc/profile.d/bash_completion.sh ]] && . /usr/local/etc/pro$:/Users/seherfazlioglu/Applications/quarto/bin:/Library/TeX/texbin:/usr/texbin:/Applications/RStudio.app/Contents/Resources/app/quarto/bin:/Applications/RStudio.app/Contents/Resources/app/bin/postback"
Sys.setenv(TAR="internal")
install.packages("fansi")
sh: tar: command not found
Warning in install.packages :
error in running command
Warning in install.packages :
'tar' returned non-zero exit code 127
Error in install.packages : file ‘/var/folders/6h/6_3mc0f97ksds4kp7c783yvc0000gn/T//RtmpCwFeYK/downloaded_packages/fansi_1.0.5.tgz’ is not a macOS binary package.

What is your assessment?
Best
Seher

What is the way suggested by Posit? What is the output of this?

R.home()

You have a broken setup. Wherever you or some software sets PATH to that value is wrong. Try setting PATH to a sane value, e.g. from R:

Sys.setenv(PATH = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin")
install.packages("fansi")

Hi Gabor,

Thanks for your suggestions. I downloaded R via this website, https://cran.rstudio.com for Mac OS, then downloaded Rstudio. Please find the outputs for your questions below:

R.home()
[1] "/Library/Frameworks/R.framework/Resources"

Setting PATH has worked. I have no error message, but got this one: "The downloaded binary packages are in
/var/folders/6h/6_3mc0f97ksds4kp7c783yvc0000gn/T//RtmpPEXEvM/downloaded_packages". Secondly, for packages there are user library and system library sections.

Do you think it is ok and i can work with this setup?
Best
Seher

I think you need to fix it properly, because it will bite you later if you don't.

Some more questions. What do you get if you run

echo $PATH

from a terminal? (Not an RStution terminal, a regular Apple Terminal.)

Do you have an .Renviron file? Do you set PATH in it? E.g. in R run this:

writeLines(readLines("~/.Renviron"))

(Make sure you do not post passwords, tokens, etc. if you have any in .Renviron.)

Hi Gabor,

You are right, the problem is not fixed properly yet. I have run the codes you asked for:

echo $PATH
/usr/bin:/Users/seherfazlioglu/anaconda3/bin:/Users/seherfazlioglu/anaconda3/condabin:/usr/local/bin:/usr/local/opt/openjdk/bin:/bin:/usr/bin:usr/local/bin:sbin:/Users$ [[ -r /usr/local/etc/profile.d/bash_completion.sh ]] && . /usr/local/etc/pro$
> writeLines(readLines("~/.Renviron"))
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/Users/seherfazlioglu/.Renviron': No such file or directory.

Anacoda makes things more complicated. Or i changed the set-up in wrong direction. What is next for now?

Thanks for your time
Best
Seher

Ah, you are using anaconda. In general, then you have two choices:

  • deactivate conda while using "regular R", or
  • installing R from anaconda

(RStudio is fine with anaconda R on macOS, AFAIR.)

As for the messed up PATH, it seems like some anaconda startup file messes it up. Maybe a bug in anaconda, I don't know. Or you copy-pasted something and that was messed up. The

Users$ [[ -r /usr/local/etc/profile.d/bash_completion.sh ]] && . /usr/local/etc/pro$

should certainly not be in your PATH.

If you are setting PATH in your shell profile, e.g. in ~/.profile, or in ~/.zshrc, then that's probably where the mistake is.

2 Likes

Hi Gabor,

Ok, i will try install R from anaconda. regarding to the bug, i need some time to figure it out and if i have questions i post it here.

Thanks again for your time and help.
Kind regards
Seher

1 Like

Hi Gabor,

I have tried to install R via Anaconda, but it failed. I had better start to fix the PATH as you suggested.

I have been searching in the web, could not find clear instructions. Do you have any suggestions on how to reset origional PATH? and do you think that it is ok to do so( e.g. not corrupting any other packages).

Kind regards
Seher

Try to find where you set the path. Look at ~/.profile and ~/.zshrc, or try to search for bash_completion.sh in Finder.

1 Like

Hi Gabor,

I have fixed it by resetting the path and install R via Anaconda.
Thanks for your inputs.
Kind regards
Seher

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.