R Package V8

Have some fun with JavaScript emoji library using the V8 R package.

🈢 some πŸ’ƒ with JavaScript emoji πŸ“™ πŸ‡ΊπŸ‡Έ the V8 R πŸ“¦.

Installation in Ubuntu 18.04

Instruction: https://github.com/nodesource/distributions/blob/master/README.md

  1. Install libnode-dev
    sudo add-apt-repository ppa:cran/v8
    sudo apt-get update
    sudo apt-get install libnode-dev
    
  2. Install snap version of nodejs
    sudo snap install node --classic --channel=8
    
  3. Install V8 package
install.packages("V8")
library(V8)
## Using V8 engine 6.8.275.32-node.12

emoji-translate

Translate text to emoji https://github.com/notwaldorf/emoji-translate

  1. Wrap moji-translate
    npm install moji-translate
    echo "global.emoji = require('moji-translate');" > in.js
    browserify in.js -o bundle.js
    
  2. Load JavaScript library in V8
ct <- v8()
ct$source("bundle.js")
## [1] "function o(i,f){if(!n[i]){if(!e[i]){var c=\"function\"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error(\"Cannot find module '\"+i+\"'\");throw a.code=\"MODULE_NOT_FOUND\",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}"
ct$get(JS('Object.keys(global)'))
## [1] "print"   "console" "global"  "emoji"
ct$call("emoji.translate", "the house is on fire and the cat is eating the cake")
## [1] "the πŸšͺ is πŸ”› πŸ“› and the πŸ™€ is 🍽 the πŸŽ‚ "



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • cmdAgent
  • cmd2cwl
  • Question-Answering Engine with CrewAI and SearXNG
  • RAG with langchain and free google gemini
  • Retrieval augmented generation