cmdstanr
cmdstanr copied to clipboard
Error when ~/.cmdstan has a folder inside but no cmdstan installation
The scenario when the error occurs is:
- ~/.cmdstan has a custom folder inside that is not a CmdStan installation,
- ~/.cmdstan has no valid CmdStan installation
The error:
Error: package or namespace load failed for ‘cmdstanr’:
.onLoad failed in loadNamespace() for 'cmdstanr', details:
call: if (endsWith(path, "/")) {
error: missing value where TRUE/FALSE needed
Thanks to @heckendorfc for pointing it out.
Hi,
I tried installing cmdstanr on a new machine and encountered the same issue. Is there a solution?
Many thanks in advance.
> install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
Installing package into ‘C:/Users/Users/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://mc-stan.org/r-packages/bin/windows/contrib/4.2/cmdstanr_0.5.3.zip'
Content type 'application/zip' length 1116495 bytes (1.1 MB)
downloaded 1.1 MB
package ‘cmdstanr’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Users\AppData\Local\Temp\RtmpSm8lwG\downloaded_packages
> cmdstanr::install_cmdstan()
Error: .onLoad failed in loadNamespace() for 'cmdstanr', details:
call: if (endsWith(path, "/")) {
error: missing value where TRUE/FALSE needed
> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.utf8 LC_CTYPE=English_Canada.utf8 LC_MONETARY=English_Canada.utf8
[4] LC_NUMERIC=C LC_TIME=English_Canada.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] pillar_1.8.1 compiler_4.2.1 prettyunits_1.1.1 remotes_2.4.2 tools_4.2.1
[6] pkgbuild_1.3.1 lifecycle_1.0.1 tibble_3.1.8 gtable_0.3.1 checkmate_2.1.0
[11] pkgconfig_2.0.3 rlang_1.0.5 cli_3.3.0 DBI_1.1.3 rstudioapi_0.14
[16] curl_4.3.2 xfun_0.32 withr_2.5.0 dplyr_1.0.10 knitr_1.40
[21] generics_0.1.3 vctrs_0.4.1 rprojroot_2.0.3 grid_4.2.1 tidyselect_1.1.2
[26] glue_1.6.2 R6_2.5.1 processx_3.7.0 fansi_1.0.3 distributional_0.3.1
[31] tensorA_0.36.2 callr_3.7.2 ggplot2_3.3.6 farver_2.1.1 purrr_0.3.4
[36] posterior_1.3.0 magrittr_2.0.3 ps_1.7.1 backports_1.4.1 scales_1.2.1
[41] abind_1.4-5 assertthat_0.2.1 colorspace_2.0-3 utf8_1.2.2 munsell_0.5.0
[46] crayon_1.5.1
Removing ~/.cmdstan
might work.
Hi @heckendorfc ,
Could you elaborate a bit more please?
There is no ~/.cmdstan
in my .libPaths()
There might be a directory called .cmdstan in your home directory that cmdstanr tries to install to.
@heckendorfc
I was unclear.
The installation for cmdstanr
worked but I cannot load the package.
> install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
Installing package into ‘C:/Users/Users/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
also installing the dependencies ‘generics’, ‘numDeriv’, ‘abind’, ‘tensorA’, ‘distributional’, ‘data.table’, ‘posterior’
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/generics_0.1.3.zip'
Content type 'application/zip' length 80429 bytes (78 KB)
downloaded 78 KB
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/numDeriv_2016.8-1.1.zip'
Content type 'application/zip' length 116102 bytes (113 KB)
downloaded 113 KB
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/abind_1.4-5.zip'
Content type 'application/zip' length 63750 bytes (62 KB)
downloaded 62 KB
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/tensorA_0.36.2.zip'
Content type 'application/zip' length 223171 bytes (217 KB)
downloaded 217 KB
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/distributional_0.3.1.zip'
Content type 'application/zip' length 544338 bytes (531 KB)
downloaded 531 KB
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/data.table_1.14.2.zip'
Content type 'application/zip' length 2243013 bytes (2.1 MB)
downloaded 2.1 MB
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/posterior_1.3.1.zip'
Content type 'application/zip' length 783311 bytes (764 KB)
downloaded 764 KB
trying URL 'https://mc-stan.org/r-packages/bin/windows/contrib/4.2/cmdstanr_0.5.3.zip'
Content type 'application/zip' length 1116495 bytes (1.1 MB)
downloaded 1.1 MB
package ‘generics’ successfully unpacked and MD5 sums checked
package ‘numDeriv’ successfully unpacked and MD5 sums checked
package ‘abind’ successfully unpacked and MD5 sums checked
package ‘tensorA’ successfully unpacked and MD5 sums checked
package ‘distributional’ successfully unpacked and MD5 sums checked
package ‘data.table’ successfully unpacked and MD5 sums checked
package ‘posterior’ successfully unpacked and MD5 sums checked
package ‘cmdstanr’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Users\AppData\Local\Temp\RtmpMJomZy\downloaded_packages
But I cannot load the package
> library(cmdstanr)
Error: package or namespace load failed for ‘cmdstanr’:
.onLoad failed in loadNamespace() for 'cmdstanr', details:
call: if (endsWith(path, "/")) {
error: missing value where TRUE/FALSE needed
There is no directory called .cmdstan
anywhere on my computer.
Maybe you're using a different installation directory, you can read about it here: https://github.com/stan-dev/cmdstanr/blob/master/R/path.R#L18
Directories starting with . are often hidden so you might not be seeing it even if it exists.
@heckendorfc
Thank you for the info.
I'm under the impression that I need to run cmdstanr::install_cmdstan()
from the cmdstanr package to install cmdstan.
I cannot even get that step to work:
> cmdstanr::install_cmdstan()
Error: .onLoad failed in loadNamespace() for 'cmdstanr', details:
call: if (endsWith(path, "/")) {
error: missing value where TRUE/FALSE needed
Yes, you can't load the package until you fix the directory I mentioned.
list.files("~/.cmdstan")
I list.files(all.files = TRUE, recursive = TRUE)
my R.home("home")
and .libPaths()
.
There's no ".cmdstan"
not your R.home or .libPaths, your user's home directory. Sys.getenv("HOME")
Still no luck
> f <- list.files(Sys.getenv("HOME"), all.files = TRUE, recursive = TRUE)
> grep("cmdstan", x = f, value = TRUE)
character(0)
You want to grep
for .cmdstan
(note the .
at the front)
@andrjohns I understand, but it's not there.
> f <- list.files(Sys.getenv("HOME"), all.files = TRUE, recursive = TRUE)
> grep("cmdstan", x = f, value = TRUE)
character(0)
> grep(".cmdstan", x = f, value = TRUE)
character(0)
> x <- c(".cmdstan", "cmdstan")
> grep("cmdstan", x = x, value = TRUE)
[1] ".cmdstan" "cmdstan"
I was also hit by this. I used to have this as part of a docker build
process, and it used to work:
install.packages("cmdstanr", repos = "https://mc-stan.org/r-packages/")
dir.create(Sys.getenv("CMDSTAN"), showWarnings = FALSE)
cmdstanr::install_cmdstan(Sys.getenv("CMDSTAN"))
But now the package loading (triggered by cmdstanr::install_cmdstan()
fails, as the .cmdstan
directory exists but doesn't contain a valid installation:
Error: .onLoad failed in loadNamespace() for 'cmdstanr', details:
call: if (dir.exists(path)) {
error: argument is of length zero
Execution halted
I fixed it by manually loading the package before creating the directory:
install.packages("cmdstanr", repos = "https://mc-stan.org/r-packages/")
library(cmdstanr)
dir.create(Sys.getenv("CMDSTAN"), showWarnings = FALSE)
cmdstanr::install_cmdstan(Sys.getenv("CMDSTAN"))
(Removing the dir.create()
doesn't help, as install_cmdstan()
fails if the directory doesn't exist. So it really needs to be 1. install cmdstanr, 2. load cmdstanr, 3. create directory, 4. install cmdstan. It would be great if it wasn't this fragile.)