Run an R Function on Chunks of Rows

post

/api/r-scripts/v1/row-apply/{scriptName}

Runs a user-owned R function on data chunked in sets of rows.

Request

Supported Media Types
Path Parameters
Body ()
A JSON str of (name - value) pairs specifying arguments of the request and additional arguments to the script
Root Schema : EmbedScriptComputeRow
Type: object
Show Source
Example Request (application/json)
{"input":"GRADE", "rows":5, "parameters":"{\"ore.na.omit\":true}", "parallelFlag":true}
Back to Top

Response

Supported Media Types

200 Response

By default, returns the job result.
Body ()
Root Schema : JSONObject
Type: object
Show Source

201 Response

If asyncFlag=True, returns the location header where the status of the job can be fetched.
Headers

400 Response

Invalid parameters specified, output exceeding size limit or other script execution error.
Body ()
Root Schema : InvalidParameterValueException
Type: object
Show Source

500 Response

Problem connecting to Broker, executing job or other unexpected error.
Body ()
Root Schema : ComputeContainerException
Type: object
Show Source
Back to Top

Examples

Example 1

The following example runs the script named my.predict.

curl -i -X POST --header "Authorization: Bearer ${token}" \
--header 'Content-Type: application/json' --header 'Accept: application/json' \
-d '{"input":"IRIS", "rows":50, "parallelFlag":true, "service":"MEDIUM"}' \
"<oml-cloud-service-location-url>/oml/api/r-scripts/v1/row-apply/my.predict"

Response Headers

The response headers are the following:

HTTP/1.1 200 OK
Date: Thu, 28 Jul 2022 21:04:18 GMT
Content-Type: application/json
Content-Length: 1820
Connection: keep-alive
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1;mode=block
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
Content-Security-Policy: frame-ancestors 'none'

Response Body

The a portion of the response body in JSON format is the following:

{"result":[{"PRED":4.7227,"Sepal.Length":4.6},{"PRED":4.5396,"Sepal.Length":4.3},{"PRED":4.6902,"Sepal.Length":5},{"PRED":5.0869,"Sepal.Length":5.8},{"PRED":4.6739,"Sepal.Length":4.4},{"PRED":4.7731,"Sepal.Length":4.4},...

Example 2

The following example runs the script named test_ggplot2_inp.

curl -i -k -X POST --header "Authorization: Bearer ${token}" --header
'Content-Type: application/json' --header 'Accept: application/json' -d
'{"input": "IRIS", "rows": 50, "envName": "myrenv", "graphicsFlag": true}'
"<oml-cloud-service-location-url>/oml/api/r-scripts/v1/row-apply/test_ggplot2_inp"

Response Body

The result of the REST endpoint is a JSON representation of the value returned from the R script, which includes the image and the data. Image bytes are returned in PNG format.

{
  "result": [
    [
      {
        "IMAGE": "iVBORw0KGgoAAAANS......qvvO1KucmjAAAAABJRU5ErkJggg==",
        "DATA": "\"hello world\"",
        "ID": 1,
        "CHUNK": "1"
      }
    ],
    [
      {
        "IMAGE": "iVBORw0KGgoAAAANSUh......UyJNE4H73kAAAAASUVORK5CYII=",
        "DATA": "\"hello world\"",
        "ID": 1,
        "CHUNK": "2"
      }
    ],
    [
      {
        "IMAGE": "iVBORw0KGgoAAAANSUh......tVBunecewAAAABJRU5ErkJggg==",
        "DATA": "\"hello world\"",
        "ID": 1,
        "CHUNK": "3"
      }
    ]
  ]
}
Back to Top