Executing a JavaScript command within an R package had become a common practice among

I am looking to create identicons using the Jdenticon library within an R package. I want a function that takes certain arguments stored in R variables, such as the output file name, and returns a filename corresponding to the generated Jdenticon (in either PNG or SVG format) that can be used, for example, in Rmarkdown documents.

Therefore, I need a function that works like this:

create_jdenticon('dj23idfsb', size = 100, format = 'svg')
# [1] "/var/folders/59/r7wjy0gn6yv59w19694x5gy80000gp/T//RtmpjDwDfq/jdenticon_dj23idfsb_100.svg"

I believe I can write most of the R function myself, but I am unsure about how to set up and execute the npx command required within R (or if this is even the correct approach).

I have noticed that the packer package includes an npx command, but I am uncertain if this package meets my needs or where to begin.

Any guidance on this matter would be greatly appreciated.

[The reason I specify Jdenticons specifically is because I am already utilizing Jdenticons elsewhere on my website, and it is essential that the generated identicons match (hence solutions using different R packages that produce unique identicons will not suffice).]

Answer №1

Check out this simplified version of Jdenticon for use with R:

https://github.com/mattroumaya/jdenticon

To integrate a Node.js package like this into your R code, follow these steps:

  1. Install node dependencies in your package's inst folder.
  2. Create any necessary JavaScript scripts to be used by your R package.
  3. Develop an R function that can call your JavaScript functions using the processx package.
  4. Package everything together to eliminate the need for R users to run npm install or set up node_modules.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to submit a textarea with the enter key without needing to refresh the page

I'm attempting to handle the submission of a textarea when the user hits the enter key, storing the text in a variable, then swapping out the form with the text and adding a new form at the end, all without refreshing. I had success doing this with an ...

Using JavaScript to pass a variable into a Promise

I am currently working on a project in EmberJS that involves making an Ajax request to fetch information and then resolving based on a specific part of the response that may vary. return new Promise((resolve, reject) => { const { resourceName, i ...

The error message "TextEncoder is not defined with mongodb nodes" is indicating that there is

Encountering an issue while running jest test cases: Getting the error message - ReferenceError: TextEncoder is not defined. Current Node version being used is 14.18.0. Mongodb NPM package version is 4.1.3. Typescript version installed is 4.4.3. Here ...

Encountering a hydration issue with an SVG element embedded within a Link component in Next

I'm encountering a hydration error related to an icon within a link, Here is the error message: Error: Hydration failed because the initial UI does not match what was rendered on the server. Warning: Expected server HTML to contain a matching <svg ...

Tips for making dropdowns stay visible in Vue.js with Tailwind CSS

Looking to create a dropdown menu using Vue.js and Tailwind CSS. Currently, when hovering over the "Genres" link, the dropdown appears but disappears as soon as the mouse moves away. Is there a way to keep it visible as long as the mouse is over the dropdo ...

How come my attempts to make my jQuery fade in upon button click aren't working?

#rock { display: none; position: relative; left: 49.4% } #paper { display: none; position: relative; left: 49%; bottom: 81px; } #scissors { display: none; position: relative; left: 48.14%; bottom: 162px; } #shoot { display: none; ...

Using jQuery's toggle function with a double click event to change the display to none

A div I created has the ability to expand to full screen upon double click, and I now wish to implement a toggle function so it can return to its original size when double clicked again. Initially, the code successfully increased the size of the div. Howe ...

Tips on using the array.map method to transform an array of arrays into an array of objects

As a React user, I am dealing with an array within the Redux Persist reducer: const data = [["2020-09-14","15:00","60","Info","April Tucker","Other","yes"],["2020-09-14"," ...

Updating React state via child components

Encountering a strange issue while working on a project, I managed to replicate it in this jsfiddle. The parent component's state seems to be affected when the child component updates its state. Any insights on what might be causing this? Here is the ...

Issue with updating dropdown values in real-time in React

I am a beginner with React and I have a question regarding fetching dropdown values from the backend. Despite using async-await functions, the list is not getting populated with items. Any assistance in this matter would be greatly appreciated. Here is th ...

Shifting axios requests outside of the React Component

Do you think this approach in React could be considered an anti-pattern? How would you suggest improving it? In my project, I utilize an EventItem Component along with a separate helper file named EventHelper.js to manage all axios calls related to the co ...

What's the reason the bootstrap tooltip style isn't displaying?

Seeking assistance with styling text in a bootstrap tooltip. My request is straightforward: I would like the text in the tooltip on the first button to be displayed in red color. I have used data-html="true" attribute to allow HTML in the tooltip. Howev ...

Could the process.exit hook be causing an endless loop?

When it comes to exiting a Node.js process, the native exit hook is essential: process.on('exit', function () { // listening for exit event }); This hook is typically triggered by calling process.exit(); // may perform some magical cleanup b ...

Preserve setTimeout() Functionality Across Page Refreshes and Navigations

I am trying to display an alert message after a 15-minute delay, but the functionality is disrupted when the page refreshes or if I navigate to a different page. This all takes place on a single web page. When a specific button is clicked, it should trig ...

Using Typescript to define the return value of an object's key value pair

Having just created the method getSpecificPlacementOption, I am faced with defining its return value in Typescript. As a newcomer to this language, I find myself unsure of how to go about it. Within my object called placementOptions, I aim to return a spec ...

The function rfm_table_order is included in the 'rfm' package

I've encountered an error message while running the code snippets below. Any help would be greatly appreciated. I suspect the problem lies in the date conversion. Thank you in advance for your assistance! > # data structure > str(bmdata) ' ...

Unable to access API due to CORS Policy issues in a Node.js application

I encountered a CORS policy error while attempting to link my React web application to my Node.js server due to different endpoints. To address this issue, I attempted to utilize CORS, a Node.js package that provides a Connect/Express middleware for enabl ...

When invoking a Javascript function within an onclick event, make sure to avoid creating a new

There's a function named save in my code that is responsible for saving data from a timer. The Model class looks like this: var Schema = mongoose.Schema; var Timer = new Schema({ Time: {type: Number}, Desc: {type: String}, Doc: {type: S ...

Could Express be considered the most reliable and efficient application framework for NodeJS?

While I have some experience with Express, I haven't explored many other Node-based web application frameworks. It's clear that Express is lightweight and versatile, but my usage has been limited to small experimental projects rather than large-s ...

What is the best way to transform a CSS tab UI into a navigation bar?

Looking to transform these tabs into a fixed Bootstrap navigation bar at the bottom. Despite my efforts, they remain fixed at the top. How can I achieve this layout with the elements at my disposal? Thank you. You can view the incorrect page here. Tab "One ...