r-universe-org / help

Support and bug tracker for R-universe
https://docs.r-universe.dev/
8 stars 2 forks source link

Package `splancs` listed as available but failed to be loaded in webR #414

Open TengMCing opened 1 month ago

TengMCing commented 1 month ago

The package splancs is listed as available on https://rsbivand.r-universe.dev/splancs for both r-4.4-emscripten and r-4.3-emscripten. However, when I try to install and load the library on https://webr.r-wasm.org/latest/ (R 4.4) and https://webr.r-wasm.org/v0.3.0/ (R 4.3.3) an error will occur.

> install.packages('splancs', repos = c('https://rsbivand.r-universe.dev', 'https://repo.r-wasm.org'))
Downloading webR package: lattice
Downloading webR package: sp
Downloading webR package: splancs
> library(splancs)
Loading required package: sp
Error: package or namespace load failed for ‘splancs’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/lib/R/library/splancs/libs/splancs.so':
  Could not load dynamic lib: /usr/lib/R/library/splancs/libs/splancs.so
Error: bad export type for 'bounds_': undefined

Did I install it incorrectly? Or is the build broken?

jeroen commented 1 day ago

Sorry for the latest response.

I think this package is broken (probably something with the fortran compilation, which is tricky). The splancs package is also unavailable on https://repo.r-wasm.org/ so that might have the same reason.

However I am not sure why our build succeeds. Perhaps @georgestagg does some additional testing before publishing the package on https://repo.r-wasm.org/.

georgestagg commented 8 hours ago

Hi @TengMCing,

The splancs package does not currently work with WebAssembly. Jeroen is right, it's a problem in the Fortran compilation:

Our Fortran compiler, LLVM flang, does not currently support emitting symbols defined in Fortran COMMON blocks. In splancs, the file cncvwt.f imports bounds.h, which indeed contains a common block. Common blocks are an older feature of Fortran, equivalent in nature to global variables.

In the past, I have had some luck converting Fortran common blocks into Fortran 95-style modules. The maintainer may or may not want to look into that. Otherwise, we will need to wait until our WebAssembly Fortran compiler is developed enough to emit global symbols from such blocks.


P.S. I compile packages using a slightly different architechture to r-universe for repo.r-wasm.org, so sometimes we get slightly different results - particularly when a package is broken.