Installing Rstan on windows virtual machine

I am trying to install Rstan on a windows data science virtual machine on azure to increase the computation times of my bayesian analysis. I followed the github tutorial on how to install rstan again but I am running into some problems.
When I run the school examples using"

     fit <- stan(model_code = eightschools,
               data = schools_dat, iter = 10000, warmup = 100, chains = 4)

I get the following error:

Error in system(cmd, intern = !verbose) : 
  'C:/PROGRA~1/Microsoft/ML' not found
Error in sink(type = "output") : invalid connection

I searched the entire internet but I don’t know how to fix it. When I test using:

fx <- inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ‘
return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
’ )
fx( 2L, 5 ) # should be 10

I get the error:

Error in system(cmd, intern = !verbose) : 
  'C:/PROGRA~1/Microsoft/ML' not found

I did however note that I don’t have a MakeVars file in any directory on my virtual machine and executing the following command (from Newbie installation problem)

file.path(Sys.getenv("HOME"), ".R", "Makevars")

results in a directory on my local pc and not on my virtual machine. Does anyone know how to solve these errors and to get stan to work on my virtual machine? Many thanks in advance!!!

What is the result of

pkgbuild::has_build_tools(debug = TRUE)

?

@bgoodri Thanks for your help!

When I run

pkgbuild::has_build_tools(debug = TRUE)

it returns TRUE. I think this is also what it should be?

OK. Now do the inline example with verbose = TRUE, i.e.

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
  return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
', verbose = TRUE)

What is the whole error message?

@bgoodri

This returns me the following error and warning messages:

Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: running command 'C:/PROGRA~1/Microsoft/ML Server/R_SERVER/bin/x64/R CMD SHLIB file1618443fdf1.cpp 2> file1618443fdf1.cpp.err.txt' had status 127 
2: In file(con, "r") :
  cannot open file 'file1618443fdf1.cpp.err.txt': No such file or directory

OK. What about

pkgbuild::with_build_tools(
fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
  return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
', verbose = TRUE), debug = TRUE, required = FALSE )

@bgoodri

This returns the following:

 >> Program source :

   1 : 
   2 : // includes from the plugin
   3 : #include <R.h>
   4 : #include <Rdefines.h>
   5 : #include <R_ext/Error.h>
   6 : 
   7 : 
   8 : // user includes
   9 : 
  10 : 
  11 : // declarations
  12 : extern "C" {
  13 : SEXP file160417c439d5( SEXP x, SEXP y) ;
  14 : }
  15 : 
  16 : // definition
  17 : 
  18 : SEXP file160417c439d5( SEXP x, SEXP y ){
  19 : 
  20 :                                return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
  21 :                                 
  22 : Rf_warning("your C++ program does not return anything"); 
  23 :  return R_NilValue ; 
  24 : }
  25 : 
  26 : 
Compilation argument:
 C:/PROGRA~1/Microsoft/ML Server/R_SERVER/bin/x64/R CMD SHLIB file160417c439d5.cpp 2> file160417c439d5.cpp.err.txt 
Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: running command 'C:/PROGRA~1/Microsoft/ML Server/R_SERVER/bin/x64/R CMD SHLIB file160417c439d5.cpp 2> file160417c439d5.cpp.err.txt' had status 127 
2: In file(con, "r") :
  cannot open file 'file160417c439d5.cpp.err.txt': No such file or directory

I believe the problem is the space between ML and Server

Is it possible to install Microsoft R without that space?

@bgoodri

This solved the problem! Thank you so much!!!

hi, @c5v
Could you tell us how did you solved it?

I have exactly the same problem, Thanks
Francisco