The following code to produces a WebSocket which outputs received messages in the R console:
ws <- WebSocket$new(""ws://echo.websocket.org/"")
ws$onMessage(function(event) {
cat(event$data)
})
I'm trying to find a way to assign the message received from the WebSocket server to an object in R (preferably as a character vector). I've tried to following:
ws$onMessage(function(event) {
testobject<-cat(event$data)
})
and
ws$onMessage(function(event) {
testobject<-capture.output(cat(event$data))
})
But neither of these approaches work. I'm aware that the sink()
function can be used to transfer the console output to file format, but I'm hoping to use WebSocket data to update my R environment in real time. Is there any approach that will work for this case?