{"action":"created","issue":{"url":"https://api.github.com/repos/trestletech/plumber/issues/16","labels_url":"https://api.github.com/repos/trestletech/plumber/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/trestletech/plumber/issues/16/comments","events_url":"https://api.github.com/repos/trestletech/plumber/issues/16/events","html_url":"https://github.com/trestletech/plumber/issues/16","id":95428012,"number":16,"title":"Error: object of type 'closure' is not subsettable","user":{"login":"jochenvanwylick","id":3002474,"avatar_url":"https://avatars.githubusercontent.com/u/3002474?v=3","gravatar_id":"","url":"https://api.github.com/users/jochenvanwylick","html_url":"https://github.com/jochenvanwylick","followers_url":"https://api.github.com/users/jochenvanwylick/followers","following_url":"https://api.github.com/users/jochenvanwylick/following{/other_user}","gists_url":"https://api.github.com/users/jochenvanwylick/gists{/gist_id}","starred_url":"https://api.github.com/users/jochenvanwylick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jochenvanwylick/subscriptions","organizations_url":"https://api.github.com/users/jochenvanwylick/orgs","repos_url":"https://api.github.com/users/jochenvanwylick/repos","events_url":"https://api.github.com/users/jochenvanwylick/events{/privacy}","received_events_url":"https://api.github.com/users/jochenvanwylick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-07-16T13:00:26Z","updated_at":"2015-07-16T14:43:42Z","closed_at":null,"body":"Thanks for this cool library - exactly what I've been looking for. However - I've got a bit of an issue, I get the following error message:\r\n\r\n> {\"error\":[\"500 - Internal server error\"],\"message\":[\"object of type 'closure' is not subsettable\"]}\r\n\r\nOr more detailed:\r\n\r\n> simpleError in data$PriceEUR: object of type 'closure' is not subsettable\r\n\r\nHere's my code:\r\n\r\n````R\r\n#' @get /predict\r\ndoPredict <- function(from, to, price, ndtf, type = \"response\") {\r\n  getTree <- function(from, to) {\r\n    varname <- paste0(from, \"_\", to);\r\n    return(eval(parse(text=varname)));\r\n  }\r\n  \r\n\ttree <- getTree(from, to);\r\n\r\n\t# Creates a data frame from the parameters\r\n\tPriceEUR <- c(as.integer(price));\r\n\tNumDaysToFlight <- c(as.integer(ndtf));\r\n\ts  <- data.frame(PriceEUR, NumDaysToFlight);\r\n\r\n\t# Return the predicted value\r\n\tvalue <- predict(tree,1,s,type = type)\r\n\treturn(value);\r\n}\r\n````\r\n\r\nWhen I run this code locally - it works. Return type of the prediction call is an integer.\r\n\r\nHowever, when called from the webserver, I get the error mentioned above. Am I doing something wrong or did I hit an issue?"},"comment":{"url":"https://api.github.com/repos/trestletech/plumber/issues/comments/121977732","html_url":"https://github.com/trestletech/plumber/issues/16#issuecomment-121977732","issue_url":"https://api.github.com/repos/trestletech/plumber/issues/16","id":121977732,"user":{"login":"trestletech","id":1593639,"avatar_url":"https://avatars.githubusercontent.com/u/1593639?v=3","gravatar_id":"","url":"https://api.github.com/users/trestletech","html_url":"https://github.com/trestletech","followers_url":"https://api.github.com/users/trestletech/followers","following_url":"https://api.github.com/users/trestletech/following{/other_user}","gists_url":"https://api.github.com/users/trestletech/gists{/gist_id}","starred_url":"https://api.github.com/users/trestletech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trestletech/subscriptions","organizations_url":"https://api.github.com/users/trestletech/orgs","repos_url":"https://api.github.com/users/trestletech/repos","events_url":"https://api.github.com/users/trestletech/events{/privacy}","received_events_url":"https://api.github.com/users/trestletech/received_events","type":"User","site_admin":false},"created_at":"2015-07-16T14:43:42Z","updated_at":"2015-07-16T14:43:42Z","body":"The one problem that I see in your script is that you're assigning the variable into the Global environment. plumber is going to run the server within its own environment, so you'd probably be safer just using a regular assignment there:\r\n\r\n```\r\nAMS_ACC <- readRDS(\"~/Downloads/example/AMS_ACC.rds\")\r\n```\r\n\r\nWhen I use this file it works for me.\r\n\r\n```\r\nlibrary(partykit)\r\n\r\nAMS_ACC <- readRDS(\"~/Downloads/example/AMS_ACC.rds\")\r\n\r\n#' @get /predict\r\ndoPredict <- function(from, to, price, ndtf, type = \"response\") {\r\n  getTree <- function(from, to) {\r\n    varname <- paste0(from, \"_\", to);\r\n    return(eval(parse(text=varname)));\r\n  }\r\n\r\n  tree <- getTree(from, to);\r\n\r\n  # Creates a data frame from the parameters\r\n  PriceEUR <- c(as.integer(price));\r\n  NumDaysToFlight <- c(as.integer(ndtf));\r\n  s  <- data.frame(PriceEUR, NumDaysToFlight);\r\n\r\n  # Return the predicted value\r\n  value <- predict(tree,s,type = type)\r\n  return(value);\r\n}\r\n```\r\n\r\n```\r\np <- plumb(\"theAboveFile\")\r\np$run()\r\n```\r\n\r\nHere's the curl command generated by Chrome\r\n\r\n```\r\ncurl 'http://localhost:8000/predict?from=AMS&to=ACC&price=123&ndtf=12&type=response' -H 'Pragma: no-cache' -H 'DNT: 1' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H Connection: keep-alive' --compressed\r\n```\r\n\r\nand the response:\r\n```\r\n[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.3182,1.3182,1.3182,1,1.1087,1.3182,1.3182,1.1087,1.1087,1.1087,1.1087,1.1087,1.1087,1.1087,1.1087,1.1087,1.1087,1,1,1.1087,1,1.1087,1.1087,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.3182,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.3182,1.3182,1.3182,1,1.1087,1.3182,1.3182,1.3182,1.1087,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.1087,1,1.1087,1.1087,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]\r\n```\r\n\r\nThe file you sent over in `functions.R` is different from the one you originally provided and I'd expect would have some problems (since it doesn't convert the characters into integers/numerics, for instance)."}}