Hi, and welcome!
A good rule of thumb on Mac is to turn down the option to compile from source. It sometimes works, but when it doesn't, it is very unlikely that the user will either be able, due to lack of C/C++ programming skills, or willing, due to the time involved, to make the required edits to the source code. Saint Simon Urbanek from the R Core Development Team takes on that burden for us, in most cases of packages on CRAN in active development. It usually only takes 10-14 days after a new version is released.
On the other hand, sometimes it does work. But there are two things you need to do.
- Download the free XCode app from the App Store
- Open a terminal window and give the following command
$ xcode-select -p
You should do this everytime there's a new XCode available.