Errors when installing rstan on windows

I am trying to install rstan on windows but run into multiple problems. Firstly, when I run pkgbuild::has_build_tools(debug = TRUE) it returns FALSE. Also, when I try to run the schools example fit <- rstan::stan(file = '8schools.stan', data = schools_dat, chains = 4, iter = 10000, warmup = 5000), I get the following error:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/user/Documents/R/R-3.6.1/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_log.hpp:5:0,
                 from C:/Users/user/Documents/R/R-3.6.1/library/StanHeaders/include/stan/math/prim/mat.hpp:278,
                 from C:/Users/user/Documents/R/R-3.6.1/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
                 from C:/Users/user/Documents/R/R-3.6.1/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Users/user/Documents/R/R-3.6.1/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file6c404aad10b6.cpp:14:

Anyone an idea what could be wrong?

Do

install.packages("inline")
example(stan_model, package = "rstan", run.dontrun = TRUE)

and tell us what part of the output starts with error: as well as the stuff under “make would do …”

@bgoodri thanks for your help.

The error is:

Error in compileCode(f, code, language = language, verbose = verbose) : 
sh: line 6: /Rtools/bin/sed: Permission deniedsh: line 6: /Rtools/bin/sed: Permission deniedsh: 
line 6: /Rtools/bin/sed: Permission deniedsh: line 8: C:/Rtools/mingw_64/bin/g++: Permission 
deniedsh: line 9: /Rtools/bin/rm: 
Permission deniedmake: *** [C:/Users/user/DOCUME~1/R/R-36~1.1/share/make/winshlib.mk:13: file46644b642506.dll] Error 126

The “Permission denied” stuff is not a good sign. Which user installed RTools on that machine?

@bgoodri I installed RTools by myself.

Does anything with RTools work, like

example(cxxfunction, package = "inline", run.dontrun = TRUE)

?

This returns the following error message

Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Warning message:In system(cmd) : 'make' not found

That means the toolchain is not working I would try uninstalling all RTools and reinstalling RTools.