Skip to content
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

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

Open
ColinFay opened this issue Jul 11, 2024 · 2 comments
Open

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

ColinFay opened this issue Jul 11, 2024 · 2 comments
Labels
feature New feature or request

Comments

@ColinFay
Copy link
Contributor

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 ColinFay changed the title feat: migrate the library logic from spidyr to webr feat: migrate the library() logic from spidyr to webr Jul 11, 2024
@georgestagg
Copy link
Member

georgestagg commented Jul 14, 2024

Sounds like a great feature! My only additional suggestion would be that, similar to other webR APIs, the library() JS function is made accessible through the instantiated webR object:

  const webR = new WebR();
  await webR.init();
  let tools = await webR.library("tools");
  let result = await tools.toTitleCase(["hello from r"]);

Yes, feel free to make an intial PR and we'll go from there.

@georgestagg georgestagg added the feature New feature or request label Jul 14, 2024
@ColinFay
Copy link
Contributor Author

Awesome!

I'll be on vacation for the next two weeks but I'll work on this as soon as I get back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants