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
- Install
libnode-dev
sudo add-apt-repository ppa:cran/v8 sudo apt-get update sudo apt-get install libnode-dev
- Install snap version of
nodejs
sudo snap install node --classic --channel=8
- 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
- Wrap
moji-translate
npm install moji-translate echo "global.emoji = require('moji-translate');" > in.js browserify in.js -o bundle.js
- 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: