Do I have to rewrite my script?
Available — v0.0.1 (experimental)r
Use the tool you already have
An R script that reads stdin and writes stdout is already a valid pipe. Values 10, 20, 30 in; count, mean, median and sd out.
Available in v0.0.1: the files, README and tests are in examples/r-summary of the openflange-go repository. Commands run from the repository root.
Needs: Rscript with the jsonlite package.
A pipe is a data-processing step with declared inputs and outputs.
What goes in, what comes out
Input (stdin)
{"value":10}
{"value":20}
{"value":30}Command — an ordinary Unix pipe
printf '%s\n' '{"value":10}' '{"value":20}' '{"value":30}' | Rscript --vanilla examples/r-summary/summary.ROutput (stdout)
{"count":3,"mean":20,"median":20,"sd":10}Files and further commands
The same script through the runner
printf '%s\n' '{"value":10}' '{"value":20}' '{"value":30}' | openflange run ./examples/r-summary --grant subprocessA bad record, skipped on request
printf '%s\n' '{"value":10}' '{"value":"n/a"}' '{"value":30}' | openflange run ./examples/r-summary --grant subprocess --param onInvalid=skip
# {"count":2,"mean":20,"median":20,"sd":14.142135623731,"skipped":1}What to notice
- The first command involves no OpenFlange software: one input on stdin, one output on stdout, diagnostics on stderr, exit code 0 for success. That is the whole CLI protocol for a simple pipe.
- Through the runner the output is the same, and the runner also checks the contract, the parameters and the
subprocesspermission. Without--grant subprocessit refuses withE_PERMISSION(exit status 2). - A
valuethat is missing or not a number fails the run and names the record.--param onInvalid=skipleaves such records out and counts them inskipped. - This script reads the whole input before answering (
scope: dataset), so memory grows with the input. That is declared, not hidden; the bounded variant is the moving-window example. - The repository verified it with R 4.5.3 and jsonlite 2.0.0. It was not re-run for this page.