简体   繁体   中英

how to pass the arguments in R using opencpu

HI i am calling R program as a webservice using opencpu.when i call the program or passing the argument it shows timeout exception.This is my program.

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
}

i am creaing a new package in r

package.skeleton(list = c("test"),environment = .GlobalEnv,code_files = character(),name="addresstest")

i am passing the argument by curl

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

It is not working.i am new to r and opencpu . any help will be appreciated.

You can try something like this:

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

It ends with this message : R call did not return within 90 seconds. Terminating process. R call did not return within 90 seconds. Terminating process.

Are you sure that function itself as described in test method is finishing in less then 90 sec? Also I don't see where do you use argument data at all in the method?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM