webr icon indicating copy to clipboard operation
webr copied to clipboard

feat: migrate the `library()` logic from `spidyr` to `webr`

Open ColinFay opened this issue 1 year ago • 2 comments

spidyr currently supports doing the following:

const tools = await library("tools"); 
const res = await tools.toTitleCase(["hello from r"]);

Or more elegantly, imho :

const { toTitleCase } = await library("tools");
const res = await toTitleCase(["hello from r"]);

As we discussed offline, there might be no good reason for it to be specific to the NodeJS runtime, we could definitely benefit from it being natively integrated to webR, so that we could have it in the browser too:

// target code 
<script type="module" >
  import('https://webr.r-wasm.org/latest/webr.mjs').then(
  async ({WebR}) => {
      const webR = new WebR();
      await webR.init();
      let tools = await library("tools");
      let result = await tools.toTitleCase(["hello from r"]);
    }
  );
</script>

Current code exists at https://github.com/ColinFay/spidyr/blob/main/src/library.js

Happy to work on a PR for integrating this directly into webR

ColinFay avatar Jul 11 '24 17:07 ColinFay