-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
Super awesome |
There was a problem hiding this 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.
packages/webr/R/mount.R
Outdated
#' @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". |
There was a problem hiding this comment.
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.
Thanks for the review!
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 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 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 I will think some more about this before merging. |
In the browser, this allows images built using Emscripten's
file_packager
tool to be mounted on the webR virtual filesystem usingwebR.FS.mount()
in JS, andwebr::mount()
in R. This makes use of the EmscriptenWORKERFS
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
orNODEFS
. The other Emscripten filesystem objects are currently unimplemented. Note that the environment must be correct (e.g. not allowed to useNODEFS
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.)