Error in if()

I am new to Rstan. I am trying to run the eight school example on
But getting the error
Error in if (grepl(pattern, makefile_txt[i])) { : argument is of length zero

Could anyone please help me to overcome the error please.
Any help is appreciated.


If you are using RStudio, you can execute

file.edit(file.path("~", ".R", "Makevars"))

to open that file up in the RStudio editor. What is the content of that file?

Hi @bgoodri, Thanks for the follow-up.
The Makevars says

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = (BINPREF)g++ -m(WIN) -std=c++1y
CXX11FLAGS=-O3 -Wno-unused-variable -Wno-unused-function




is an empty string?

returned " "


OK. This is going to take some effort to debug. Can you tell me the output of



Thanks for the quick reply.
says NULL

OK. That should not happen. Can you start with line 28 at

and print the output for each of the lines in that function?

out ← system2(file.path(Sys.getenv(“R_HOME”), “bin”, “R”), + args = “CMD SHLIB --dry-run”, stdout = TRUE)[2] ;


“CMD.EXE was started with the above path as the current directory.”

Do I need to run the “makefiles” function after this too?

Probably not. What is just file.path(Sys.getenv("R_HOME"), "bin", "R")?

that says ,

How about normalizePath(file.path(Sys.getenv("R_HOME"), "bin", "R"))?

[quote=“bgoodri, post:12, topic:6138”]

normalizePath(file.path(Sys.getenv(“R_HOME”), “bin”, “R”))

[1] “C:\PROGRA~1\R\R-35~1.1\bin\R”
Warning message: In normalizePath(path.expand(path), winslash, mustWork) :
path[1]=“C:/PROGRA~1/R/R-35~1.1/bin/R”: The system cannot find the file specified

This is very weird. So, in C:/Program Files/ I guess you have a directory called R. Can you look what is under that directory in the Windows Explorer file manager?

Under R folder, a subfolder called R-3.5.1 is seen, which again has subfolders
bin, doc ,etc, include, library, modules, share, src, Tcl, tests.

Additionally, files called
CHANGES, COPYING, MD5, README, README.R-3.5.1, unins000.dat, unins000.exe

are seen.

Argh. Maybe what is the entire output of

system2(file.path(Sys.getenv("R_HOME"), "bin", "R"),
               args = "CMD SHLIB --dry-run", stdout = TRUE)

system2(file.path(Sys.getenv(“R_HOME”), “bin”, “R”),
args = “CMD SHLIB --dry-run”, stdout = TRUE)

It gives

“’\\…\documents\StaffHome\StaffGroups$\…\Documents\about dengue project\my_analysis\Stan\Rstan eg’”

[2] “CMD.EXE was started with the above path as the current directory.”
[3] “UNC paths are not supported. Defaulting to Windows directory.”
[4] “make cmd is”
[5] " make -f “C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-35~1.1/share/make/” -f “//…/documents/StaffHome/StaffGroups$/…/Documents/.R/Makevars” SHLIB="" WIN=64 TCLBIN=64 OBJECTS="""
[6] “”
[7] “make would use”
[8] “make: Nothing to be done for `all’.”
Here I have put three dots (…) at some directories, which are personal.

OK. This “UNC paths are not supported. Defaulting to Windows directory.” should not be happening. It is not directly related to Stan but is preventing Stan from working correctly. If you google for that exact quote, there are many hits. If that is a work computer, you might have to speak to an IT person. Until then, if you just want to play around with Stan, you can do so online at
which is already configured correctly.

Thanks for your help.

I am trying to run simple Stan examples for two weeks with no success.
The link gives me a blank page.

Any reason why its blank ?