-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FS.mount() throws an error when trying to mount local files with WORKERFS #328
Comments
Here is a reprex = https://github.com/ColinFay/webr-mount-reprex |
Same happens if I try to reproduce the code from the documentation, using fetch : const { WebR } = require('webr');
const webR = new WebR();
(async () => {
await webR.init();
// Create mountpoint
await webR.FS.mkdir('/data')
// Download image data
const data = await fetch('https://raw.githubusercontent.com/ColinFay/webr-mount-reprex/main/iris.data');
const metadata = await fetch('https://raw.githubusercontent.com/ColinFay/webr-mount-reprex/main/iris.js.metadata');
// Mount image data
const options = {
packages: [{
blob: await data.blob(),
metadata: await metadata.json(),
}],
}
await webR.FS.mount("WORKERFS", options, '/data');
})();
|
Thank you for reporting this and for the example, I can reproduce the bug at my end. It looks like the issue is specific to using the In the meantime, I know it might not be quite what you had in mind, but you should be able to use the alternative First, write the data you're interested in to disk in a new directory, $ mkdir data
$ Rscript -e 'write.csv(iris, "data/iris.csv")' Then, mount the new directory with const { WebR } = require('webr');
const webR = new WebR();
(async () => {
await webR.init();
await webR.FS.mkdir('/data');
await webR.FS.mount("NODEFS", { root: './data' }, '/data');
await webR.evalRVoid("print(head(read.csv('/data/iris.csv')))")
process.exit(1);
})();
|
Yeah this is what I've been doing so far (see https://colinfay.me/rethinking-packages-and-functions-preloading-in-webr-0.2.2/ for ex) but I want to package some stuff into a node module, and I feel like it would be better to upload the |
Instead, use our own `mountImageData()` function to create VFS nodes for each file in the VFS metadata package. TODO: This currently handles only metadata given in the form of the `packages` property. Emscripten supports additional `files` and `blobs` properties, and in the future we should also support those here. Fixes #328.
As of 4655e96, to be included in the next release of webR, mounting Note that in your original test script, the argument of const data = new Blob([
fs.readFileSync(
path.join(__dirname, 'iris.data')
)
]); It should also work when passing the Here is essentially the test script I've been using. Once we cut a new release of webR and it hits npm you should be able to try it out for yourself. const fs = require('fs');
const path = require('path');
const { WebR } = require('webr');
const webR = new WebR();
(async () => {
await webR.init();
const data = new Blob([
fs.readFileSync(
path.join(__dirname, 'iris.data')
)
])
const metadata = JSON.parse(
fs.readFileSync(
path.join(__dirname, 'iris.js.metadata')
)
);
await webR.FS.mkdir('/data');
const options = {
packages: [{
blob: data,
metadata: metadata,
}],
}
await webR.FS.mount("WORKERFS", options, '/data');
await webR.evalRVoid("print(file.info('/data/iris.csv'))")
await webR.evalRVoid("print(head(read.csv('/data/iris.csv')))")
process.exit(1);
})(); |
Following the example from https://docs.r-wasm.org/webr/latest/mounting.html#javascript-api
Here is a reprex.
Step 1, using the
ghcr.io/r-wasm/webr
image :Step 2, move to a node js script and try to load from disk
Even if both
data
andmetadata
areconsole.log
ed, the process throws an error :I've tried using
But get the same result
The text was updated successfully, but these errors were encountered: