Stateful Agent
1
Stateful R code to be called remotely
library("vrpc")
dataset <- NULL
select_dataset <- function(name) {
dataset <<- switch(name,
"rock" = rock,
"pressure" = pressure,
"cars" = cars
)
return(TRUE)
}
get_summary <- function() {
summary(dataset)
}
get_table <- function(obs) {
head(dataset, n = obs)
}
start_vrpc_agent(domain = "public.vrpc")2
Call R code and manage state
const { VrpcRemote } = require('vrpc')
if (process.argv.length < 3) {
console.log('Usage: node index.js <agentName>')
process.exit(1)
}
(async () => {
const client = new VrpcRemote({
domain: 'public.vrpc',
agent: process.argv[2]
})
await client.connect()
const proxy = await client.create({
className: 'Session',
instance: 'session1'
})
await proxy.select_dataset('rock')
await proxy.get_table(1) // first line of rock dataset
await proxy.select_dataset('cars')
await proxy.get_table(2) // first two lines of cars dataset
await proxy.get_summary() // summary information of cats dataset
})()Last updated