How to run Javascript code in R Studio

Please, how do I run a piece of Javascript code in R Studio? I have created a Javascript file, and in it, I have the code below I want to run:

if(true){
let x = 5;
var y = 3;
}

However, I do not know how to run this code in R Studio. Does anybody know, please?

Hmm, I don't think RStudio can directly run Javascript? You can use RStudio to write Javascript code, to then run it with your web browser.

Or within R, there is the V8 package that provides access to a Javascript engine. This is useful if you need Javascript and R code to communicate. For example:

ct <- v8()
ct$eval("if(true){
let x = 5;
var y = 3;
}
console.log(y)")
#> 3

But overall, if writing pure Javascript, I don't know if RStudio is the best tool?

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.