kaskr / adcomp

AD computation with Template Model Builder (TMB)
Other
178 stars 81 forks source link

TMB fails under Web R: "cannot open the connection [...] /usr/lib/R/library/TMB/Matrix-version" #392

Closed adrianolszewski closed 7 months ago

adrianolszewski commented 8 months ago

Hello, Is it possible to change the code of TMB to fix the problem it causes under the Web R (webassembly)? Web R allows one to run R code just within the web browser, without calling any external server.

The issue makes also all dependent packages, like mmrm (core package to analyze longitudinal data in clinicaltrials), unable to load under Web R.

Related issue: https://github.com/r-wasm/webr/issues/386

Description:

When the library is loaded under web r, it raises the following error: obraz

Reproducible Steps:

Please visit: https://webr.r-wasm.org/latest/

Type "library(TMB)" and choose to install it (1).

It will fail:

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: wasm32-unknown-emscripten (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.

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

1: Yes
2: No

Selection: 1
Downloading webR package: lattice
Downloading webR package: Matrix
Downloading webR package: Rcpp
Downloading webR package: RcppEigen
Downloading webR package: TMB
Error: package or namespace load failed for ‘TMB’:
 .onLoad failed in loadNamespace() for 'TMB', details:
  call: file(con, "w")
  error: cannot open the connection
In addition: Warning message:
cannot open file '/usr/lib/R/library/TMB/Matrix-version': Operation not permitted 
> 

Current Output:

Error: package or namespace load failed for ‘TMB’:
 .onLoad failed in loadNamespace() for 'TMB', details:
  call: file(con, "w")
  error: cannot open the connection
In addition: Warning message:
cannot open file '/usr/lib/R/library/TMB/Matrix-version': Operation not permitted 

Expected Output:

No errors should be thrown. Maybe some warning or a regular print().

TMB Version:

I'm waiting for the response from the Web R creators, but let's assume it's the latest one.

R Version:

4.3.3

Operating System:

Platform: wasm32-unknown-emscripten (32-bit) Looking at the path it reported (/usr/lib...) I guess these packages are built under some distribution of Linux.

bbolker commented 8 months ago

I don't know exactly why this is happening, but this might be resolvable by changing the upstream-package-dependency check to be more self-contained along the lines suggested here.

I don't know how the webassembly machinery works (does it take packages from CRAN? From r-universe? From the master/main HEAD on GitHub?), but would be willing to make a pull request along these lines if desired.

Someone who knew more about the internals of webassembly might be able to diagnose the problem better.

adrianolszewski commented 8 months ago

Thank you very much! I forwarded your response to the source topic https://github.com/r-wasm/webr/issues/386#issuecomment-2021346571

kaskr commented 8 months ago

I know for sure that TMB did work in webr around 6 months ago. Something regarding write permissions to the package folder has changed in webr since then.

kaskr commented 7 months ago

After CRAN submission (1.9.11), TMB now works again on webr.

adrianolszewski commented 7 months ago

Thank you very, very much for making it working with webR! I'm closing the issue.