Open
Description
Hello,
I've been able to create a Emscripten’s filesystem image with a small CRAN-like repo with a few R packages (haven and jsonlite) and mount from the local filesystem using node.js, as shown below.
My goal is to import data using maven and return it as JSON to javascript.
But then I'm confused how to install / access R packages from that mounted filesystem ?
const { WebR } = require('webr');
const fs = require('fs');
let webR = new WebR();
await webR.init();
await webR.FS.mkdir('/localrepo');
let data = fs.readFileSync('/some/local/path/output/vfs/output.data');
let metadata = JSON.parse(fs.readFileSync('/some/local/path/output/vfs/output.js.metadata', 'utf-8'));
await webR.FS.mount(
"WORKERFS",
{
packages: [{
blob: data,
metadata: metadata,
}],
},
'/localrepo'
);
I can see the src
and bin
subfolders in the mounted filesystem image:
> res = await webR.evalR('list.files("/localrepo")')
Proxy [
{
obj: { type: 'character', ptr: 26422256, methods: [Array] },
payloadType: 'ptr'
},
{ get: [Function: get], apply: [AsyncFunction: apply] }
]
> await res.toArray()
[ 'bin', 'src' ]
I tried the following but it failed:
> await webR.installPackages(['haven', 'jsonlite'], {
... mount: false,
... quiet: false,
... repos: [
... '/localrepo'
... ]
... });
Warning message:
URL /localrepo/bin/emscripten/contrib/4.4/PACKAGES.rds: Download failed. See the Javascript console for further information
Warning message:
URL /localrepo/bin/emscripten/contrib/4.4/PACKAGES.gz: Download failed. See the Javascript console for further information
Warning message:
URL /localrepo/bin/emscripten/contrib/4.4/PACKAGES: Download failed. See the Javascript console for further information
Warning message:
unable to access index for repository /localrepo/bin/emscripten/contrib/4.4:
download from '/localrepo/bin/emscripten/contrib/4.4/PACKAGES' failed
Warning message:
Requested package haven not found in webR binary repo.
and
> res = await webR.evalR('install.packages(c("jsonlite", "haven"), repos = "file:///localrepo")')
Uncaught:
Error: Error in `utils::download.file(path, tmp, quiet = TRUE)`: download from '///localrepo/bin/emscripten/contrib/4.4/jsonlite_1.8.9.tgz' failed
Thanks a lot for your help!