For macOS, R packages come in two flavors: binary and source. Whenever presented with a choice, choose binary. If installing from source with the proper configuration, you can still expect many failures.
To fix this, you would need XCode from the app store at a version compatible with High Sierra, install its command line tool
$ xcode-select --install
On the Linux distributions, packages are installed from source by default and mainly just compile fine. Under macOS, it can be a challenge.