I'm far from being an expert in R. I had a similar problem with installing packages that need to be compiled and got no good advice in the web. I had rTools installed but I noticed that it was a version higher than the corresponding for my R version (as is stated in https://cran.r-project.org/bin/windows/Rtools/). I decided to uninstall the more advanced versions of rTools and install the corresponding for my current R version and now everything seems to work well and I have ceased to get the "ERROR:compilation failed for package ..."