Best Website Builders CompanyBest Website Builders Company
    What's Hot

    Realty stocks fall after RBI MPC keeps repo rate unchanged; Nifty Realty tumbles, DLF, Macrotech sink

    June 9, 2023

    What homebuyers should do now as RBI keeps repo rate unchanged

    June 8, 2023

    Pause in rate hikes to instill a sense of optimism among borrowers

    June 8, 2023
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    Best Website Builders CompanyBest Website Builders Company
    • Home
    • Web Builders
      1. Joomla
      2. WordPress
      3. CSS
      4. Web Design
      5. UX
      6. PHP
      7. View All

      For $50 you can host your website for life

      May 2, 2023

      California Department of Justice Investigating Shooting Involving CHP Officer in Glenn County Under AB 1506

      May 1, 2023

      Mariposa County Daily Sheriff and Reservation Report for Sunday, April 30, 2023

      May 1, 2023

      Top 10 Best Web Development Companies In India In 2023

      May 1, 2023

      Google Ads Sign Up – Easy Steps to Create Your Account

      May 17, 2023

      1Password puts users at ease after the horror of password change notifications

      May 3, 2023

      Samsung Galaxy S23 FE could feature a 50MP main camera, but we may have to wait until then

      May 3, 2023

      Titanfall director says Respawn is ‘looking forward to something new’

      May 3, 2023

      Implementing CSS with character and spirit: Union MoS Finance

      May 3, 2023

      Street Fighter 6’s unique character select screen animation really shows how much heart goes into the game

      May 3, 2023

      Make Google Chrome run faster with these 9 tips and tweaks

      May 3, 2023

      🅰️ New Angular 16 Goes Big in 2023: Everything You Need to Know | Vitaly Shevchuk | Oct 25, 2017 May 2023

      May 3, 2023

      18-Wheeler Accidents: Fatalities and Injuries

      May 6, 2023

      What Comes First in Website Development — Design or Copy?

      February 2, 2023

      Modern Campus Honors Best Higher Education Websites of 2022

      February 2, 2023

      Premier SEO Consultant in Las Vegas, Nevada with Unparalleled Customer Service

      February 2, 2023

      The role of artificial intelligence in improving the user experience in online casinos.

      May 3, 2023

      Microsoft enhances user experience with Windows 11 ‘smart opt-out’ and improved emergency notifications

      May 3, 2023

      Nigeria’s Nestcoin Launches New Digital Financial Platform For Africans

      May 3, 2023

      ibi WebFOCUS 9.2 is ready for Modern Business Intelligence, the Cloud, and Driving User Experience – PCR.

      May 3, 2023

      Anthony Carrigan Reflects on That ‘Barry’ Scene from Season 4 Episode 4

      May 1, 2023

      TikToker Kat Abu is very happy that Tucker Carlson has been fired

      April 28, 2023

      How ‘Single Drunk Female’ Season 2 Tackled Emotional Sobriety

      April 24, 2023

      Trans-Missouri Residents Affected by Attorney General Order

      April 24, 2023

      Creating and Adding a Google Account: A Step-by-Step Guide

      May 2, 2023

      How i Create New Google Account

      February 7, 2023

      CWT powers tools for meeting and event planners

      January 31, 2023

      Best Website Builder – Website Builders

      January 24, 2023
    • Realtoz
      • Our Other Sites
    • More News
    • Investments
    Best Website Builders CompanyBest Website Builders Company
    Home»JavaScript»Move away from using (most) WebR R functions in WebR-powered apps/sites and call a single JavaScript function
    JavaScript

    Move away from using (most) WebR R functions in WebR-powered apps/sites and call a single JavaScript function

    websitebuildersnowBy websitebuildersnowMarch 21, 2023No Comments4 Mins Read
    Facebook Twitter LinkedIn Telegram Pinterest Tumblr Reddit WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    After writing the first version of the tutorial on wrapping and binding R functions on the JavaScript side of WebR, I had a few other WebR projects on my TODO list. However, I’ve been thinking about “wrapping and binding” for a long time and realized that there is a “very easy” way to make R functions available in JavaScript using javascript’s Function() constructor. I was. I’ll eventually put all of this into the GH webr-experiments repo, but see below and just view the source (as of this post, re: line #’s in the 130’s) please. before that.

    Create dynamic JavaScript functions

    of Function() Constructors have many modes, one of which is to provide the entire function source and allow the function to be constructed. R folks likely know that you can do it in R (see: my {curlconverter} pkg), and it’s just as easy on the JavaScript side. Open the DevTools console and enter:

    const sayHello = new Function('return function (name) { return `Hello, ${name}` }')();
    

    Then call the function with the string value.

    Only one input is required to create a dynamic R function wrapper (SUPER BASIC R functions only). Yes, I really mean you can do this:

    let rbeta = await wrapRFunction("rbeta");
    await rbeta(10, 1, 1, 0)
    

    Returns results in WebR way toJs() The function returns an R object.

    {
      "type": "double",
      "names": null,
      "values": [
        0.9398577840605595,
        0.42045006265859153,
        0.26946718094298633,
        0.3913958406551122,
        0.8123499099597378,
        0.49116132695862963,
        0.754970193716774,
        0.2952198011408607,
        0.11734111483990002,
        0.6263863870230043
      ]
    }
    

    full dress

    Mr. R formals() You can use function to get the argument list to a function, including default values. I don’t use them in this MVP version of the autowrapper, but I see no reason why they can’t be used in later iterations. Making JavaScript functions the “hard way” is “easy”.

    async function formals(rFunctionName) {
      let result = await globalThis.webR.evalR(`formals(${rFunctionName})`);
      let output = await result.toJs();
      return(Promise.resolve(output))
    }
    

    Now we need to build the function using these names. It’s an ugly little function, but it really does a few basic things:

    async function wrapRFunction(rFunctionName) {
      let f = await formals(rFunctionName)
      let argNames = f.names.filter(argName => argName != '...');
      let params = argNames.join(', ')
      let env = argNames.map(name => `${name}: ${name}`).join(', ');
      let fbody =
      `return async function ${rFunctionName}(${params}) {
        let result = await globalThis.webR.evalR(
          '${rFunctionName}(${params})',
          { env: { ${env} }}
       );
        let output = await result.toJs();
        globalThis.webR.destroy(result);
        return Promise.resolve(output);
      }`;
      return new Function(fbody)()
    }
    
    • First, get the form of the provided function name
    • Then remove the ones you can’t handle (yet!)
    • Next, get the parameter names of the R function and create two objects.
      • Something that creates a comma-separated list of parameter declarations (e.g. param1, param2, param3)
      • Another one that does the same thing, but key: value Pairs to pass as environments (see previous WebR blog post and experiments)
    • The function body is another template string that creates standard WebR set operations for evaluating R objects and retrieving values.

    the constructed function string to Function() It’s a constructor and has an automatic JavaScript wrapper for it.

    fin

    this is very rustic rapper.it’s all up to the caller to specify all worth it. R has some fun features like the ability to check if a value is missing on the R side without specifying a value for a particular parameter. You can also mix named and positional parameters. ....

    I’ll explain and/or go a little further on how best to implement it ^^, but as I continue to experiment I’ll end up using this idiom to wrap my R functions.

    One more thing: I had to abandon the use of microlight Syntax highlighter. It’s very small and fast, but I can’t handle the code I need, so I plan to update the initial webr-template to incorporate what I’m currently using: Shiki. It also contains wrapper functions.

    *** This is a Security Bloggers Network syndicated blog on rud.is created by hrbrmstr. Read the original post: https://rud.is/b/2023/03/21/youre-one-javascript-function-call-away-from-using-most-webr-r-functions-in-your- webr-powered-apps-sites/



    Source link

    Share this:

    • Tweet
    • More
    • WhatsApp
    • Print
    • Share on Tumblr
    • Mastodon

    Related

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email
    Previous ArticleIs Duolingo developing a new music-learning app? We interpret the signs
    Next Article Martina Navratilova: Tennis legend says she is ‘cancer-free’ after treatment
    websitebuildersnow
    • Website

    Related Posts

    Fake ChatGPT extension to steal victim’s account details

    May 2, 2023

    What to expect from ECMAScript 2023 (ES14)

    May 2, 2023

    Which one is right for your project?

    May 2, 2023
    Add A Comment

    Leave a Reply Cancel reply

    Post Your Ad Free
    Advertisement
    Demo
    Top Posts

    Subscribe to Updates

    Get the latest sports news from SportsSite about soccer, football and tennis.

    This website provides information about CSS and other things. Keep Supporting Us With the Latest News and we Will Provide the Best Of Our To Makes You Updated All Around The World News. Keep Sporting US.

    Facebook Twitter Instagram Pinterest YouTube
    Top Insights

    Realty stocks fall after RBI MPC keeps repo rate unchanged; Nifty Realty tumbles, DLF, Macrotech sink

    June 9, 2023

    What homebuyers should do now as RBI keeps repo rate unchanged

    June 8, 2023

    Pause in rate hikes to instill a sense of optimism among borrowers

    June 8, 2023
    Get Informed

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    © 2023 bestwebsite-builders. Designed by bestwebsite-builders.
    • Home
    • About us
    • Contact us
    • DMCA
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.

    Go to mobile version
    x