You must have a local X server, so get XQuartz because you are on MacOS.
If you were on Ubuntu, you could install an X11 virtual server for buffer servers, for example here :
apt-get install xvfb xauth xfonts-base
Now that you have X virtual framebuffer installed, you can start a new instance, for example here :
Xvfb :0 -ac -screen 0 1960x2000x24 &
Then, if your R is compiled with the with-x configuration parameter (enabled by default), you should have the X11 capability, and you just need to declare this in R:
Sys.setenv("DISPLAY"=":0")
source share