How to install libpng-dev on Mac

Processes not started from a shell may not inherit environment variables from that shell. Start R in Terminal to make sure that your R process inherits PATH from the Terminal shell where you have run which. Something like

$ Rscript -e "install.packages(\"png\")"

should work, though you may need to select a CRAN mirror, in which case the above will throw an error. You can do that in the install.packages call, like so:

$ Rscript -e "install.packages(\"png\", repos = \"https://cloud.r-project.org\")"

or by setting a global option, like so:

$ Rscript -e "options(repos = \"https://cloud.r-project.org\"); install.packages(\"png\")"

For details, see the R for macOS FAQ and ?options.