rstanarm as part of a jamovi module

Everything related to the development of modules in jamovi
Post Reply
karruo
Posts: 2
Joined: Fri Mar 14, 2025 8:36 am

rstanarm as part of a jamovi module

Post by karruo »

Hi,
I am trying to add a rstanarm functions (mainly stan_glm and stan_glmer) to a jamovi module to provide probabilistic estimation. However, when I am trying to install (and compile) the module I get errors about rstanarm installation failing. The specific errors I get are listed below. I am running MacBook and R version 4.4.2 (2024-10-31) and jamovi version 2.6.26.

I have read that the installation script of rstanarm differs from many other in that it assumes the working directory is the root of the package directory and setting R_HOME may conflict with this - now I am unsure if jamovi jmvtools::install() sets the working directory and this could be the trouble. I hope someone could help or just tell me that using rstanarm in a jamovi module is not possible.

regards, Kari

*********
An extract of the install/compilation output on R console:

* installing *source* package ‘rstanarm’ ...
** package ‘rstanarm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C++ compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.6)’
using C++17
using SDK: ‘MacOSX15.2.sdk’
"/Applications/jamovi.app/Contents/Frameworks/R.framework/Versions/Current/Resources/bin/../bin/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/bernoulli.stan
WARNING: ignoring environment value of R_HOME
Wrote C++ file "stan_files/bernoulli.cc"


clang++ -arch x86_64 -std=gnu++17 -I"/Applications/jamovi.app/Contents/Frameworks/R.framework/Versions/Current/Resources/bin/../include" -DNDEBUG -I"../inst/include" -I"/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -DUSE_STANC3 -D_HAS_AUTO_PTR_ETC=0 -I'/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/StanHeaders/include' -I'/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/rstan/include' -I'/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/BH/include' -I'/Applications/jamovi.app/Contents/Resources/modules/base/R/Rcpp/include' -I'/Applications/jamovi.app/Contents/Resources/modules/jmv/R/RcppEigen/include' -I'/Applications/jamovi.app/Contents/Resources/modules/jmv/R/RcppParallel/include' -I/opt/R/x86_64/include WARNING: ignoring environment value of R_HOME WARNING: ignoring environment value of R_HOME -I'/Applications/jamovi.app/Contents/Resources/modules/jmv/R/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS -fPIC -falign-functions=64 -Wall -g -O2 -c stan_files/bernoulli.cc -o stan_files/bernoulli.o
clang++: error: no such file or directory: 'WARNING:'
clang++: error: no such file or directory: 'ignoring'
clang++: error: no such file or directory: 'environment'
clang++: error: no such file or directory: 'value'
clang++: error: no such file or directory: 'of'
clang++: error: no such file or directory: 'R_HOME'
clang++: error: no such file or directory: 'WARNING:'
clang++: error: no such file or directory: 'ignoring'
clang++: error: no such file or directory: 'environment'
clang++: error: no such file or directory: 'value'
clang++: error: no such file or directory: 'of'
clang++: error: no such file or directory: 'R_HOME'
make: *** [stan_files/bernoulli.o] Error 1
rm stan_files/bernoulli.cc
ERROR: compilation failed for package ‘rstanarm’
* removing ‘/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/rstanarm’

The downloaded source packages are in
‘/private/var/folders/ms/71twpwbs20l3p55vxqc33g2r0000gn/T/Rtmp0g2062/downloaded_packages’
Warning message:
In utils::install.packages(c("rstanarm"), lib = "/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos", :
installation of package ‘rstanarm’ had non-zero exit status
ERROR: dependency ‘rstanarm’ is not available for package ‘glmStan’
* removing ‘/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/glmStan’[/i]
User avatar
jonathon
Posts: 2821
Joined: Fri Jan 27, 2017 10:04 am

Re: rstanarm as part of a jamovi module

Post by jonathon »

Hi,

yeah, getting binary R packages to build under macOS is not a lot of fun ... but i've now taken some prebuilt versions of rstanarm from CRAN, and added them to the jamovi repo. this means it will use these preferentially, over the source version, and it shouldn't need to compile them. try that build step again, and it shouldn't need to perform that (problematic) build step.

jonathon
karruo
Posts: 2
Joined: Fri Mar 14, 2025 8:36 am

Re: rstanarm as part of a jamovi module

Post by karruo »

Hi,
Many thanks - this worked. However there is a dependent package shinystan that also needs compiling. It throws me an error assisted at the end of the message.

But if I set the number of cores by options
options(mc.cores = parallel::detectCores())
and retry the compilation, the package compiles fine and works in jamovi. So, the shnystan error is not an issue for me right now but I thought to mention it if someone else faces the same.

regards, Kari

****** error message about shinystan ********

** byte-compile and prepare package for lazy loading
sh: line 1: 27792 Segmentation fault: 11 R_TESTS= '/Applications/jamovi.app/Contents/Frameworks/R.framework/Versions/Current/Resources/bin/../bin/R' --no-save --no-restore --no-echo 2>&1 < '/var/folders/ms/71twpwbs20l3p55vxqc33g2r0000gn/T//Rtmph8cEx6/file6c795768cc05'

*** caught segfault ***
address 0x0, cause 'memory not mapped'

Traceback:
1: get_rng(0)
2: assign(x, value, envir = ns, inherits = FALSE)
3: assignInMyNamespace("RNG", value = get_rng(0))
4: fun(libname, pkgname)
5: doTryCatch(return(expr), name, parentenv, handler)
6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
7: tryCatchList(expr, classes, parentenv, handlers)
8: tryCatch(fun(libname, pkgname), error = identity)
9: runHook(".onLoad", env, package.lib, package)
10: loadNamespace(name)
11: .Internal(getRegisteredNamespace(name)) %||% loadNamespace(name)
12: getNamespace("rstan")
13: getClassDef(Class, where)
14: getClass("stanfit", where = getNamespace("rstan"))
15: is(representation, "classRepresentation")
16: setClass("stanfit", getClass("stanfit", where = getNamespace("rstan")))
17: eval(exprs, envir)
18: eval(exprs, envir)
19: sys.source(codeFile, env, keep.source = keep.source, keep.parse.data = keep.parse.data)
20: doTryCatch(return(expr), name, parentenv, handler)
21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
22: tryCatchList(expr, classes, parentenv, handlers)
23: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call, nlines = 1L) prefix <- paste("Error in", dcall, ": ") LONG <- 75L sm <- strsplit(conditionMessage(e), "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && isTRUE(getOption("show.error.messages"))) { cat(msg, file = outFile) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
24: try(sys.source(codeFile, env, keep.source = keep.source, keep.parse.data = keep.parse.data))
25: loadNamespace(package = package, lib.loc = lib.loc, keep.source = keep.source, keep.parse.data = keep.parse.data, partial = TRUE)
26: withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
27: suppressPackageStartupMessages(loadNamespace(package = package, lib.loc = lib.loc, keep.source = keep.source, keep.parse.data = keep.parse.data, partial = TRUE))
28: code2LazyLoadDB(package, lib.loc = lib.loc, keep.source = keep.source, keep.parse.data = keep.parse.data, compress = compress, set.install.dir = set.install.dir)
29: tools:::makeLazyLoading("shinystan", "/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/00LOCK-shinystan/00new", keep.source = FALSE, keep.parse.data = FALSE, set.install.dir = "/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/shinystan")
An irrecoverable exception occurred. R is aborting now ...
ERROR: lazy loading failed for package ‘shinystan’
* removing ‘/Users/kariruohonen/Documents/jamovi_modules/glmStan/build/R4.4.1-x64-macos/shinystan’
Post Reply