# NOT RUN {
# Make sure you have started Komodo Edit or IDE with the SciViews-K extension
# installed on the same machine, and the socket server started and then...
# Send JavaScript commands to Komodo
# Alert box in Komodo, and then reply to R
koCmd(c('alert("Hello from R!");',
'sv.socket.serverWrite("Hello from OpenKomodo (" + ko.interpolate.currentFilePath() + ")");'))
# Open a web page wih Komodo configuration
koCmd("ko.open.URI('about:config','browser');")
# Get info from Komodo
koCmd("sv.socket.serverWrite(ko.logging.getStack());")
# Passing a large amount of data to Komodo, and then, back to R
koCmd(paste0('sv.socket.serverWrite("', rep(paste(iris, collapse = "\\\\n"), 10), '");'))
# It is easier to use 'data =' instead of paste() for constructing the JS command
koCmd('alert("<<<data>>>");', data = search())
# Using a named list for data to replace in the cmd
koCmd('alert("This is R version <<<major>>>.<<<minor>>>");', R.version)
# Sending incorrect JavaScript instruction
koCmd('nonexistingJSfunction();')
# Should return something like:
# "ReferenceError: nonexistingJSfunction is not defined"
# Sending RJsonP (RJson with padding) instruction to Komodo
koCmd("Hello with RJsonP!", type = "rjsonp", pad = "alert")
# This is more useful to pass complex R objects to Komodo
koCmd(head(iris), type = "rjsonp", pad = "sv.socket.serverWrite")
# Send simple text (no evaluation) to the Komodo R console
koCmd("Hello again from R!", type = "output")
# }
Run the code above in your browser using DataLab