Skip to content

Expose Emscripten's FS.mount on webR's R and JS API #293

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

Merged
merged 9 commits into from
Oct 16, 2023
Merged

Conversation

georgestagg
Copy link
Member

@georgestagg georgestagg commented Oct 9, 2023

In the browser, this allows images built using Emscripten's file_packager tool to be mounted on the webR virtual filesystem using webR.FS.mount() in JS, and webr::mount() in R. This makes use of the Emscripten WORKERFS filesystem object.

Additionally, host machine directory paths can be mounted onto the VFS, enabling local file access, when webR is running under Node. This makes use of the Emscripten NODEFS filesystem object.

The exposed API allows one to choose between WORKERFS or NODEFS. The other Emscripten filesystem objects are currently unimplemented. Note that the environment must be correct (e.g. not allowed to use NODEFS in the browser) and webR will enforce this.

See https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.mount for more information.

Closes #260, in that it should be possible to set up a host directory containing a set of R packages, mount the directory somewhere when running under Node, and then finally add that mount point to R's .libPaths().

(Also fixes an unrelated documentation issue in global_prompt_install. I was going to rebase this away but it does not matter much.)

@ColinFay
Copy link
Contributor

ColinFay commented Oct 9, 2023

Super awesome

@georgestagg georgestagg requested a review from lionel- October 9, 2023 16:05
Copy link
Member

@lionel- lionel- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful! I think the API would be a bit cleaner with two different functions though. Accepting multiple types of inputs / behaviour is nice if it allows some genericity, but here that's not the case since you have to pass in a branching parameter and provide mutually exclusive arguments.

Comment on lines 20 to 25
#' @param data_url a character string giving the URL to a `.data` filesystem
#' image to be downloaded and mounted.
#' @param path a character string giving the path to a host directory to be
#' mounted.
#' @param type a character string giving the type of Emscripten filesystem to be
#' mounted: "workerfs" or "nodefs".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the API would be simpler if this were two different functions. In general we try to avoid mutually exclusive arguments like path and data_url here. This would simplify usage and the documentation.

@georgestagg
Copy link
Member Author

georgestagg commented Oct 10, 2023

Thanks for the review!

I think the API would be a bit cleaner with two different functions though.

I agree, but I'd also like to try and match the already existing Emscripten API if possible.

Though, now that I think about it, while they do have a single FS.mount() function for multiple filesystem types, they don't have the mutually exclusive arguments. Instead, there is an opts argument that changes properties depending on the context.

In our case, perhaps we could combine the arguments? They are semantically different (a URL and a directory path), but at least both strings. I guess the argument could be named something generic like source to cover all bases.

So, maybe something like,

mount <- function(mountpoint, source, type = "workerfs")

which would then be used as in,

mount("/mnt1", "./some/host/directory", type = "nodefs")
mount("/mnt2", "http://example.com/some/url.data", type = "workerfs")

On the other hand, I suppose that's just pushing complexity onto the documentation of source.

I will think some more about this before merging.

@georgestagg georgestagg merged commit 3ba2e01 into main Oct 16, 2023
@georgestagg georgestagg deleted the fs-mount branch October 16, 2023 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How do I preload the R packages in a node app?
3 participants