Fail to install cmdstanr Error: Failed to install 'unknown package' from GitHub: Line starting 'VignetteB ...' is malformed!

Hi All,

I am new to cmdstanr and even new to R. My intention is to install the “rethinking” package according to the website: GitHub - rmcelreath/rethinking: Statistical Rethinking course and book package .

I have already installed the rstan package but fail to install the cmdstanr package according to : R Interface to CmdStan • cmdstanr .

My environment is as follows

  • Windows 7
  • R 4.1.2
  • RStudio 2022.02.0+443 “Prairie Trillium” Release

I run

install.packages(“cmdstanr”, repos = c(“Repository for distributing (some) stan-dev R packages | r-packages”, getOption(“repos”)))

and it failed with this error

Warning in install.packages :
unable to access index for repository https://mc-stan.org/r-packages/src/contrib:
cannot open URL ‘https://mc-stan.org/r-packages/src/contrib/PACKAGES
Warning in install.packages :
package ‘cmdstanr’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
R Installation and Administration
Warning in install.packages :
unable to access index for repository https://mc-stan.org/r-packages/bin/windows/contrib/4.1:
cannot open URL ‘https://mc-stan.org/r-packages/bin/windows/contrib/4.1/PACKAGES

I then try

remotes::install_github(“stan-dev/cmdstanr”)

but it failed again:

Error: Failed to install ‘unknown package’ from GitHub:
Line starting ‘VignetteB …’ is malformed!

I have tried to search for solution in google and this forum but fail to find any that works for me. Can anyone please help?

Thanks!

Just want to add addition information.

I searched from google that adding the following code may help so i tried.

Sys.setenv(LANG = “en_US.UTF-8”)
remotes::install_github(“stan-dev/cmdstanr”)

Though the download started, there is any error message.

Downloading GitHub repo stan-dev/cmdstanr@HEAD
√ checking for file ‘C:\Users\user\AppData\Local\Temp\Rtmp2bceh3\remotes30ac538d508c\stan-dev-cmdstanr-b62ad1f/DESCRIPTION’ …
– preparing ‘cmdstanr’: (929ms)
√ checking DESCRIPTION meta-information …
Error in parse(con, encoding = “UTF-8”) :
invalid multibyte character in parser at line 4
Execution halted
Error: Failed to install ‘cmdstanr’ from GitHub:
System command ‘Rcmd.exe’ failed, exit status: 1, stdout & stderr were printed

Sorry for the slow reply!

Are you able to install other R packages using remotes::install_github()? For example does this work?

remotes::install_github("stan-dev/loo")

If you get a similar error there then I don’t think is related to CmdStanR and there is probably a more general issue with your windows setup (googling a bit it seems like there are other people who get the error message System command ‘Rcmd.exe’ failed when installing R packages but unrelated to CmdStanR or Stan). Unfortunately I don’t know much about Windows but may @rok_cesnovar has seen this before?

Hi Jonah

Thanks for your reply.

I gave up installing the package in that computer. Instead, I found another laptop which is running window 10 to do the installation (with R4.1.3).

This time I did successfully install cmdstanr. However, I encounter errors installing cmdstan.

install_cmdstan(cores = 2)
Error:
RTools installation found but PATH was not properly set.
Run check_cmdstan_toolchain(fix = TRUE) to fix the issue.
check_cmdstan_toolchain(fix = TRUE)
Installing mingw32-make and writing RTools path to ~/.Renviron …
Error in processx::run(“pacman”, args = c(“-Syu”, “mingw-w64-x86_64-make”, :
System command ‘pacman’ failed, exit status: 1, stderr (last 10 lines):
E> error: failed retrieving file ‘mingw64.db’ from cloud.r-project.org : SSL certificate problem: unable to get local issuer certificate
E> error: failed retrieving file ‘mingw64.db’ from cran.r-project.org : SSL certificate problem: unable to get local issuer certificate
E> error: failed to update mingw64 (download library error)
E> error: failed retrieving file ‘ucrt64.db’ from r-windows.github.io : SSL certificate problem: unable to get local issuer certificate
E> error: failed retrieving file ‘ucrt64.db’ from cloud.r-project.org : SSL certificate problem: unable to get local issuer certificate
E> error: failed retrieving file ‘ucrt64.db’ from cran.r-project.org : SSL certificate problem: unable to get local issuer certificate
E> error: failed to update ucrt64 (download library error)
E> error: failed retrieving file ‘mirrors.db’ fro
[…]
Type .Last.error.trace to see where the error occurred

Then i tried to download cmdstan directly from github and set the path with.
set_cmdstan_path(PATH_TO_CMDSTAN)

I have verified it with

cmdstan_path()
[1] “C:/Users/jchung/Documents/cmdstan-2.29.2”

Errors occur when i try to run some cmdstan function.

file ← file.path(cmdstan_path(), “examples”, “bernoulli”, “bernoulli.stan”)
mod ← cmdstan_model(file)
Compiling Stan program…
Error in rethrow_call(c_processx_exec, command, c(command, args), pty, :
Command ‘mingw32-make.exe’ not found @win/processx.c:982 (processx_exec)
Type .Last.error.trace to see where the error occurred

Any ideas?

Thanks.

This might seem like a wild idea - but is the time and date set correctly on the machine?

Hi Rok,

Thanks for your reply.

Yes, time and date are set correctly (based on my location = Hong Kong) on my laptop.

Just to add one more piece of information that i don’t have administrator right on this laptop.

Thanks.

Updates:
I tried to run the codes below again today but different issue came up.

file ← file.path(cmdstan_path(), “examples”, “bernoulli”, “bernoulli.stan”)
mod ← cmdstan_model(file)
Compiling Stan program…
INFO: Could not find files for the given pattern(s).
Error: An error occured during compilation! See the message above for more information.

I have tried other stan function and encountered the same issue.

Hi, I think the problem lies on several issues:

  1. Your laptop you used is managed by an organization and you are not the administrator. In this case, you should create the R project and install R in where you have control on (I use C disk for this, a bit risky but you can a back-up on an external storage disk)
  2. After that, everytime you install any packages, you should manually change the library path , for example, to install cmdstanr, you need to execute this code:
    “install.packages(“cmdstanr”, lib=“C:/PHUONG-1/SET-UP/R-4.1.3/library”, repos = c(“Repository for distributing (some) stan-dev R packages | r-packages”, getOption(“repos”)))”
    Remember the argument lib = you should manually fix it to where you store your R installation.
  3. After installing cmdstanr, now you can install rethinking package by
    withr::with_libpaths(new=“C:/PHUONG-1/SET-UP/R-4.1.3/library”, devtools::install_github(‘rmcelreath/rethinking’))
    Note: in the code, the argument new= needs to be manually changed to your R installation path as above

Good luck! and hope this helps. It helps me and my issues are exactly yours