Brms error: Error in Sys.setenv(R_MAKEVARS_USER = NULL) : wrong length for argument

I tried to use brms for the first time in a while, and I keep getting the same error:

Error in Sys.setenv(R_MAKEVARS_USER = NULL) : wrong length for argument

I have tried it on two different computers (both Windows), both with the most recent R version (4.2.0) and brms version (2.17), and I have tried running it through RStudio and through RGui as well.

The error occurs both with my own code and with the sample code from ?brm:

prior1 <- prior(normal(0,10), class = b) +
  prior(cauchy(0,2), class = sd)
fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
            data = epilepsy, family = poisson(), prior = prior1)

Thank you in advance!

Björn

Hello!

I have reinstalled R/RStudio/RTools/RStan/brms today and I am still getting the same error message. Elsewhere, I have found another user with the same issue (r - Why do I get "Error in Sys.setenv(R_MAKEVARS_USER = NULL) : wrong length for argument" error when trying to build a STAN model? - Stack Overflow). I followed the steps someone suggested to them (Configuring C Toolchain for Windows · stan-dev/rstan Wiki · GitHub) to no avail, I am still getting the same error even when trying to run:

example(stan_model, package = “rstan”, run.dontrun = TRUE)

Does anyone have any other ideas?

Thank you!

Sorry for missing your first post Björn! First can you post the output from the following commands (so I can check how everything is configured):

Sys.getenv("PATH")
Sys.getenv("R_MAKEVARS_USER")
readLines("~/.Renviron")
readLines("~/.Rprofile")
readLines("~/.R/Makevars.win")

Hey, thanks for the response and sorry for not checking back in sooner!

The output is the following:

Sys.getenv(“PATH”)
[1] “C:\rtools42/x86_64-w64-mingw32.static.posix/bin;C:\rtools42/usr/bin;C:\Program Files\R\R-4.2.2\bin\x64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Git LFS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Program Files\PsychoPy_2021.2.3;C:\Program Files\PsychoPy_2021.2.3\DLLs;C:\Program Files\PsychoPy 2021.2.3;C:\Program Files\PsychoPy 2021.2.3\DLLs;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\bjoer\AppData\Local\Microsoft\WindowsApps;C:\Users\bjoer\AppData\Local\GitHubDesktop\bin;C:\Users\bjoer\AppData\Local\Microsoft\WindowsApps;C:\Users\bjoer\AppData\Roaming\TinyTeX\bin\win32;C:\Users\bjoer\.dotnet\tools;C:\Users\bjoer\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\PsychoPy;C:\Program 豆岸σ飨~饠~;;C:/Program Files/RStudio/resources/app/bin/quarto/bin”
Sys.getenv(“R_MAKEVARS_USER”)
[1] “”
readLines(“~/.Renviron”)
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/bjoer/Documents/.Renviron’: No such file or directory
readLines(“~/.Rprofile”)
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/bjoer/Documents/.Rprofile’: No such file or directory
readLines(“~/.R/Makevars.win”)
[1] “” “CXX14FLAGS=-O3 -march=native -mtune=native” “CXX11FLAGS=-O3 -march=corei7 -mtune=corei7”

Hello again! Does anyone have any suggestions? I could probably even get some grant money to pay for consultancy fees, but I kinda need to get this to work as one of my projects is wrapping up and it really looks like a Bayesian analysis is the way to go there.

Can you try installing the rstan preview:

remove.packages(c("StanHeaders", "rstan"))

install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

I tried (on both of my computers) and on running the first example from the ?brm documentation I am unfortunately still getting the same error:

Error in Sys.setenv(R_MAKEVARS_USER = NULL) : wrong length for argument

Can you try installing cmdstanr:

# we recommend running this is a fresh R session or restarting your current session
install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
cmdstanr::install_cmdstan()

And then running your brms model with backend="cmdstanr"

It appears to be working now!

At first, I got the error message:

Error: CmdStan path has not been set yet. See ?set_cmdstan_path.

After looking at the ?set_cmdstan_path documentation, I tried to load cmdstanr, which led me down a tiny rabbit hole:

require(cmdstanr)
Loading required package: cmdstanr
This is cmdstanr version 0.5.3

install_cmdstan()
Error:
Rtools42 installation found but the toolchain was not installed.
Run cmdstanr::check_cmdstan_toolchain(fix = TRUE) to fix the issue.

cmdstanr::check_cmdstan_toolchain(fix = TRUE)
Installing mingw32-make and g++ with Rtools42.
The C++ toolchain required for CmdStan is setup properly!

install_cmdstan()

After the cmdstan installation finished, it would allow me to run the example model from the documentation with the added backend = “cmdstanr” as suggested:

fit1 ← brm(count ~ zAge + zBase * Trt + (1|patient), data = epilepsy, family = poisson(), prior = prior1, backend=“cmdstanr”)

So thanks again for the help!