如何使用opencpu传递R中的参数

时间:2015-09-16 12:58:45

标签: r web-services hadoop opencpu

我正在使用opencpu将R程序作为web服务调用。当我调用该程序或传递它显示超时异常的参数时。这是我的程序。

test <- function(data)
{
setwd("/home/ec2-user")
args <- commandArgs(trailing = TRUE)
delhi <- read.delim("delhi.tsv", na.strings = "")
delhi$lnprice <- log(delhi$price)
delhi$furn.f = factor(delhi$furnished)
delhi <- delhi [(delhi$facing %in% c ("East", "West", "North", "South",  "South - East",  "South -West", "North - East", "North - West", NA)),]
delhi$fac.f = factor(delhi$facing)
delhi$age.f = factor(delhi$age)
delhi$own.f = factor (delhi$ownership)
delhi <- delhi[!table(delhi$locality)[delhi$locality]<20,]
delhi$loc.f = factor(delhi$locality)
delhi$address.f = factor(delhi$propertyaddress)
delhi <- delhi [!(delhi$locality %in% c ("Sector-1")),]
model <- lm(lnprice ~ bedrooms+ address.f,data = delhi)
address <- args[1]
result <- predict (model,address)
result
}

我在r

中创建了一个新包
package.skeleton(list = c("test"),environment = .GlobalEnv,code_files = character(),name="addresstest")

我正在通过curl传递论据

http://52.25.248.111:5888/ocpu/library/addresstest/R/test/ -d "argument"

它不工作。我是r和opencpu的新手。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

curl http://52.25.248.111:5888/ocpu/library/addresstest/R/test/json -H "Content-Type: application/json" -d '{"data":"argumentValue"}'

以此消息结束:R call did not return within 90 seconds. Terminating process.

您是否确定测试方法中描述的功能本身在不到90秒内完成?另外,我在这个方法中根本没有看到你在哪里使用参数数据