r-lib / usethis

Set up commonly used 📦 components
https://usethis.r-lib.org/
Other
865 stars 286 forks source link

Running install.packages("usethis") results in "fatal error: 'git2.h' file not found". #1970

Closed markariosd3 closed 8 months ago

markariosd3 commented 8 months ago

This issue appears very similar to this one written about on March 29, 2021 https://github.com/r-lib/usethis/issues/1410#issuecomment-809839711 but I'm not doing anything with Github Actions, I'm just trying to install usethis. Based on the 2021 issue it appears that I should install libgit2 as the other advice of waiting for a new cran build doesn't make sense since the R version Angel Food Cake would have correct this error. I also pasted my console below. Can someone please kindly give me a clue on how to get past this?

Lastly, I'm sorry in advance if this isn't the right place or if I'm missing something obvious.

SYSTEM DETAILS Computer: Macbook Air Memory: 8GB Chip: Apple M1 Sonoma 14.2.1 git version 2.39.3 (Apple Git-146) Homebrew 4.2.16 /opt/brew/opt/pkg-config (appears installed here) Rstudio: Version 2023.03.1+446 (2023.03.1+446) R version 4.3.3

ERROR DETAILS

R version 4.3.3 (2024-02-29) -- "Angel Food Cake" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: aarch64-apple-darwin23.2.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.

[Workspace loaded from ~/.RData]

install.packages("usethis") Installing package into ‘/opt/homebrew/lib/R/4.3/site-library’ (as ‘lib’ is unspecified) also installing the dependency ‘gert’

trying URL 'https://cran.rstudio.com/src/contrib/gert_2.0.1.tar.gz' Content type 'application/x-gzip' length 122723 bytes (119 KB)

downloaded 119 KB

trying URL 'https://cran.rstudio.com/src/contrib/usethis_2.2.3.tar.gz' Content type 'application/x-gzip' length 371088 bytes (362 KB)

downloaded 362 KB

The downloaded source packages are in ‘/private/var/folders/2x/ynk03js54vx7vv8wgbyyzr7h0000gn/T/RtmpTuO3yB/downloaded_packages’

jennybc commented 8 months ago

FWIW this is a failure to install the gert package, from source. Installing usethis is what caused you to discover this, but you would presumably get the same result with a direct install.packages("gert"), i.e. this doesn't have anything to do with usethis.

I would zoom out a bit and ask some questions:

Here's a write-up of why we advise against homebrew for installing R:

https://github.com/rstats-wtf/what-they-forgot/blob/8205e16230ca8458c461405b43afdc0450bae584/system-prep-for-build.qmd#L69-L91

If you still want to use it for installing R, it's very important to do brew install --cask r and not brew install r.

markariosd3 commented 8 months ago

Thank you very much for pointing those issues out for me and those questions were very useful informative as well. I will reinstall. Best, Mark

On Mon, Apr 1, 2024 at 6:34 PM Jennifer (Jenny) Bryan < @.***> wrote:

FWIW this is a failure to install the gert package, from source. Installing usethis is what caused you to discover this, but you would presumably get the same result with a direct install.packages("gert"), i.e. this doesn't have anything to do with usethis.

I would zoom out a bit and ask some questions:

  • Why is install.packages() trying to install source packages instead of binary? You really shouldn't be trying to build gert unless you really want to, i.e. you should be installing the prebuild macOS binary from CRAN.
  • How did you install R from homebrew? In general, I advise against homebrew R unless you have very specific reasons you want to do that. Instead I strongly advise installing R from CRAN ( https://cran.r-project.org/) or with rig (https://github.com/r-lib/rig ).

Here's a write-up of why we advise against homebrew for installing R:

https://github.com/rstats-wtf/what-they-forgot/blob/8205e16230ca8458c461405b43afdc0450bae584/system-prep-for-build.qmd#L69-L91

If you still want to use it for installing R, it's very important to do brew install --cask r and not brew install r.

— Reply to this email directly, view it on GitHub https://github.com/r-lib/usethis/issues/1970#issuecomment-2030915789, or unsubscribe https://github.com/notifications/unsubscribe-auth/BD4HUUJOQA6RX5HB4CV3JTLY3IDI5AVCNFSM6AAAAABFSNW2D6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZQHEYTKNZYHE . You are receiving this because you authored the thread.Message ID: @.***>

loicbaron commented 2 weeks ago

On a MacOS using homebrew, install libgit2: brew install libgit2 Then install.packages("usethis"). This worked fine for me!