Problems while installing 'ragg' package in my Mac M1, which is essential for installing tidyverse and devtools

I use R 4.4.1 in VS code and in Positron. However, I can't use tidyverse and devtools because of this ragg package. Here is the error message:
install.packages("ragg")
Installing package into ‘/opt/homebrew/lib/R/4.4/site-library’
(as ‘lib’ is unspecified)

trying URL 'https://mirror.niser.ac.in/cran/src/contrib/ragg_1.3.2.tar.gz'
Content type 'application/x-gzip' length 430366 bytes (420 KB)

downloaded 420 KB

  • installing source package ‘ragg’ ...
    ** package ‘ragg’ successfully unpacked and MD5 sums checked
    ** using staged installation
    Found pkg-config cflags and libs!
    Using PKG_CFLAGS=-I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include
    Using PKG_LIBS=-L/opt/homebrew/opt/freetype/lib -L/opt/homebrew/opt/libpng/lib -L/opt/homebrew/Cellar/libtiff/4.6.0/lib -L/opt/homebrew/opt/zstd/lib -L/opt/homebrew/Cellar/xz/5.6.2/lib -L/opt/homebrew/Cellar/jpeg-turbo/3.0.3/lib -lfreetype -lbz2 -lpng16 -lz -ltiff -lzstd -llzma -ljpeg -lz -lzstd -llzma -pthread -lpthread -lz -ljpeg
    ** libs
    using C++ compiler: ‘g++-14 (Homebrew GCC 14.2.0) 14.2.0’
    using SDK: ‘MacOSX14.4.sdk’
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c capture_dev.cpp -o capture_dev.o
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c init.cpp -o init.o
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c jpeg_dev.cpp -o jpeg_dev.o
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c png_dev.cpp -o png_dev.o
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c ppm_dev.cpp -o ppm_dev.o
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c tiff_dev.cpp -o tiff_dev.o
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c agg/src/agg_curves.cpp -o agg/src/agg_curves.o
    /opt/homebrew/bin/g++-14 -I"/opt/homebrew/Cellar/r/4.4.1/lib/R/include" -DNDEBUG -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/zstd/include -I/opt/homebrew/Cellar/xz/5.6.2/include -I/opt/homebrew/Cellar/jpeg-turbo/3.0.3/include -I'/opt/homebrew/lib/R/4.4/site-library/systemfonts/include' -I'/opt/homebrew/lib/R/4.4/site-library/textshaping/include' -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include -fPIC -g -O2 -c agg/src/agg_font_freetype.cpp -o agg/src/agg_font_freetype.o
    agg/src/agg_font_freetype.cpp: In instantiation of 'bool agg::decompose_ft_outline(const FT_Outline&, bool, const trans_affine&, PathStorage&) [with PathStorage = path_storage_integer<int, 6>; FT_Outline = FT_Outline_]':
    agg/src/agg_font_freetype.cpp:1071:48: required from here
    1071 | if(decompose_ft_outline(m_cur_face->glyph->outline,
    | ^~~~~~~~
    1072 | m_flip_y,
    | ~~~~~~~~~
    1073 | m_affine,
    | ~~~~~~~~~
    1074 | m_path32))
    | ~~~~~~~~~
    agg/src/agg_font_freetype.cpp:182:35: error: invalid conversion from 'unsigned char*' to 'char*' [-fpermissive]
    182 | tags = outline.tags + first;
    | ~~^
    | |
    | unsigned char*
    agg/src/agg_font_freetype.cpp: In instantiation of 'bool agg::decompose_ft_outline(const FT_Outline&, bool, const trans_affine&, PathStorage&) [with PathStorage = path_storage_integer<short int, 6>; FT_Outline = FT_Outline_]':
    agg/src/agg_font_freetype.cpp:1092:48: required from here
    1092 | if(decompose_ft_outline(m_cur_face->glyph->outline,
    | ^
    ~
    1093 | m_flip_y,
    | ~~~~~~~~~
    1094 | m_affine,
    | ~~~~~~~~~
    1095 | m_path16))
    | ~~~~~~~~~
    agg/src/agg_font_freetype.cpp:182:35: error: invalid conversion from 'unsigned char*' to 'char*' [-fpermissive]
    182 | tags = outline.tags + first;
    | ~~~~~~~~^
    | |
    | unsigned char*
    make: *** [agg/src/agg_font_freetype.o] Error 1
    ERROR: compilation failed for package ‘ragg’
  • removing ‘/opt/homebrew/lib/R/4.4/site-library/ragg’

The downloaded source packages are in
‘/private/var/folders/9m/hkvdjwx161g_bdcnbyf807lr0000gn/T/RtmpkLwB71/downloaded_packages’
Warning message:
In install.packages("ragg") :
installation of package ‘ragg’ had non-zero exit status

I am not sure why ragg does not build with your system packages, file an issue in the ragg issue tracker if you think this is a bug in ragg.

Nevertheless, a workaround is to use the CRAN version of R, instead of the Homerrew build, then you don't need to install packages from source:

brew install r --cask

Or use GitHub - r-lib/rig: The R Installation Manager to install multiple R versions from CRAN and switch between them as you like.

If you really want to use Homebrew R, then you possibly need different versions of ragg's dependencies, or a fix in ragg.

Thanks, @Gabor after running your suggestions, now I can install tidyverse and devtools. Thank you so much.