r-wasm / webr

The statistical language R compiled to WebAssembly via Emscripten, for use in web browsers and Node.
https://docs.r-wasm.org/webr/latest/
Other
805 stars 54 forks source link

The [mmrm] package is missing in the repo (it was there previously) #391

Closed adrianolszewski closed 3 months ago

adrianolszewski commented 3 months ago

Recently I reported an issue regarding the mmrm package when running the code in https://webr.r-wasm.org/latest/ (actually caused by one of the dependencies, TMB; https://github.com/r-wasm/webr/issues/386).

Today I wanted to play in the webr editor and also in the livecode one - where mmrm loaded and worked properly.

While in the livecode.io it is loaded normally:

Loading WebR...

WebR is using `PostMessage` communication channel, nested R REPLs are not available.

WebR loaded.

Installing packages: mmrm

Downloading webR package: backports
Downloading webR package: checkmate
Downloading webR package: cli
Downloading webR package: glue
Downloading webR package: rlang
Downloading webR package: lifecycle
Downloading webR package: lattice
Downloading webR package: nlme
Downloading webR package: numDeriv
Downloading webR package: Rcpp
Downloading webR package: rbibutils
Downloading webR package: Rdpack
Downloading webR package: magrittr
Downloading webR package: stringi
Downloading webR package: vctrs
Downloading webR package: stringr
Downloading webR package: Matrix
Downloading webR package: RcppEigen
Downloading webR package: TMB
Downloading webR package: brio
Downloading webR package: ps
Downloading webR package: R6
Downloading webR package: processx
Downloading webR package: callr
Downloading webR package: desc
Downloading webR package: digest
Downloading webR package: evaluate
Downloading webR package: jsonlite
Downloading webR package: crayon
Downloading webR package: fs
Downloading webR package: pkgbuild
Downloading webR package: rprojroot
Downloading webR package: withr
Downloading webR package: pkgload
Downloading webR package: praise
Downloading webR package: diffobj
Downloading webR package: fansi
Downloading webR package: utf8
Downloading webR package: pillar
Downloading webR package: pkgconfig
Downloading webR package: tibble
Downloading webR package: rematch2
Downloading webR package: waldo
Downloading webR package: testthat
Downloading webR package: mmrm

...the web-r editor fails to load it:

> library(mmrm)
Failed to load package "mmrm". Do you want to try downloading it from the webR binary repo? 

1: Yes
2: No

Selection: Yes
Warning message:
In webr::install(package) :
  Requested package mmrm not found in webR binary repo.

I don't know if livecode.io uses own, separate version of the packages library, but if not, then something strange is happening...

Is there any chance to restore this package in future to the repository? It's one of the core packages for analysing longitudinal data in clinical trials.

PS: just thought that maybe it's related to the recent web R upgrade and needs recompiling the packages, which takes time?

georgestagg commented 3 months ago

I'll investigate to see why the app is no longer building.

In the meantime, you should still be able to load the package in the older fixed version of the app at https://webr.r-wasm.org/v0.2.2/, rather than at /latest/.

georgestagg commented 3 months ago

Due to restrictions in the WebAssembly environment, not all R packages work with webR. It looks like the last version of the mmrm package that worked with webR was version 0.2.2.

I can re-upload version 0.2.2 to the webR repository for /latest, but the package will not receive further updates for the time being.

georgestagg commented 3 months ago

I've pushed the older mmrm v0.2.2 to the webR repo for /latest, you should be able to load it there now.

Although the TMB package seems to require a compiler for full functionality, and library(TMB) does still fail, it looks like it can still be used in a limited fashion under webR. However, due to an assumption that the package makes about where it can write files it needs to be loaded in a slightly different way with an extra argument mount = FALSE.

So, please try installing and using TMB and mmrm in the following way when running in like this in https://webr.r-wasm.org/latest/ :

webr::install("TMB", mount = FALSE)
webr::install("mmrm")
webr::install("dplyr")

library(dplyr)
library(mmrm)
set.seed(0228)

d <- bind_rows(expand.grid(visit = 1:20, subject = 1:200, trt = "a") %>%
                   mutate(aval = rbeta(nrow(.), 7, 1)),
               expand.grid(visit = 1:20, subject = 201:400, trt = "b") %>%
                   mutate(aval = rbeta(nrow(.), 4, 1))) %>%
    mutate(visit = factor(visit),
           subject = factor(subject))

unique_visits <- unique(d$visit)

for (i in seq_along(unique_visits)) {
    these_rows <- which(d$visit == unique_visits[i])
    d$aval[these_rows] <- d$aval[these_rows] *
        rbinom(n = length(these_rows), size = 1, prob = 1 / as.numeric(unique_visits[i]))
}

d <- d[d$aval != 0, ]

fit1 <- mmrm(aval ~ trt + ar1(visit | subject), data = d)
summary(fit1)$coefficients
adrianolszewski commented 3 months ago

@georgestagg Thank you wholeheartedly! In the meantime, maintainers of the TMB also pushed things forward. Please check: https://github.com/r-wasm/webr/issues/386#issuecomment-2028855308

georgestagg commented 3 months ago

With the changes in #386, mmrm now seems to work. I'll close this thread as complete.

adrianolszewski commented 1 month ago

Dear @georgestagg I just tried the mmrm package in the latest web R version: https://webr.r-wasm.org/latest/ and it disappear again:

> library(mmrm)
Failed to load package "mmrm". Do you want to try downloading it from the webR binary repo? 

1: Yes
2: No

Selection: 1
Warning message:
In webr::install(package) :
  Requested package mmrm not found in webR binary repo.

I tried it 30.05.2024.

georgestagg commented 1 month ago

My apologies, this got lost in the upgrade to R v4.4.0, which required rebuilding the WebAssembly package repository for the new 4.4 series. I've just built and pushed TMB and the last known working version of mmrm (v0.2.2).

I've also made a commit to (https://github.com/r-wasm/rwasm/commit/f5fc2feb150b13601226fd0478535d67956fa2fa) pinning TMB and the slightly older mmrm versions. This should ensure they're kept in place for similar rebuilds in the future.

Please clear your browser cache and try again, mmrm should now load at https://webr.r-wasm.org/latest/ once more.