Created
July 1, 2015 08:42
-
-
Save jeroen/1984c784a6eff71f508f to your computer and use it in GitHub Desktop.
ProtoBuf over OCPU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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