Run an R Function multiple times
post
/r-scripts/v1/index-apply/{scriptName}
Runs a user-owned R Function "times" times.
Request
Path Parameters
-
scriptName(required):
The name of the R script
Response
200 Response
By default, returns the job result.
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.
500 Response
Problem connecting to Broker, executing job or other unexpected error.
Examples
Example 1
The following example runs the script named compute.randomMean
.
curl -i -X POST --header "Authorization: Bearer ${token}" \
--header 'Content-Type: application/json' --header 'Accept: application/json' \
-d '{"times":10, "parallelFlag":true,"service":"MEDIUM"}' \
"<oml-cloud-service-location-url>/oml/api/r-scripts/v1/index-apply/compute.randomMean"
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 response body in JSON format is the following:
{"result":{"1":0.1322,"2":0.2112,"3":-0.0671,"4":0.5665,"5":-0.0789,"6":0.1054,"7":0.104,"8":-0.4493,"9":-0.219,"10":-0.4907}}
Example 2
The following example runs the script named test_ggplot2_idx
.
curl -i -k -X POST --header "Authorization: Bearer ${token}" --header
'Content-Type: application/json' --header 'Accept: application/json' -d
'{"times": 2, "envName": "myrenv", "graphicsFlag": true}'
"<oml-cloudservice-location-url>/oml/api/r-scripts/v1/index-apply/test_ggplot2_idx"
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": "iVBORw0KGgoAAAANSUh......lPb3ruAAAAAElFTkSuQmCC",
"DATA": "\"hello world\"",
"TIME": "1",
"ID": 1
}
],
[
{
"IMAGE": "iVBORw0KGgoAAAANSUh......aOqfnpAAAAAElFTkSuQmCC",
"DATA": "\"hello world\"",
"TIME": "2",
"ID": 1
}
]
]
}