Skip to content

Instantly share code, notes, and snippets.

@jeroen
Created July 1, 2015 08:42
Show Gist options
  • Save jeroen/1984c784a6eff71f508f to your computer and use it in GitHub Desktop.
Save jeroen/1984c784a6eff71f508f to your computer and use it in GitHub Desktop.
ProtoBuf over OCPU
# Read data
library(httr)
library(RProtoBuf)
req <- GET("https://public.opencpu.org/ocpu/library/MASS/data/cats/pb")
cats <- unserialize_pb(req$content)
# rnorm(5, 10, 3)
payload <- list(
n = 5,
mean = 10,
sd = 3
)
# One step RPC
req <- POST("https://public.opencpu.org/ocpu/library/stats/R/rnorm/pb",
content_type("application/x-protobuf"), body = serialize_pb(payload, NULL))
stop_for_status(req)
out <- unserialize_pb(req$content)
print(out)
# Two step RPC
req1 <- POST("https://public.opencpu.org/ocpu/library/stats/R/rnorm",
content_type("application/x-protobuf"), body = serialize_pb(payload, NULL))
stop_for_status(req1)
url <- paste0(headers(req1)$location, "R/.val/pb")
req2 <- GET(url)
stop_for_status(req2)
out <- unserialize_pb(req2$content)
print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment