From 3826edfcde77eb92a47dea1b9241a657236f45bc Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Mon, 23 Nov 2020 10:37:01 -0800 Subject: [PATCH] feat(components): Added a sample R script component (#4817) --- components/sample/R_script/component.yaml | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 components/sample/R_script/component.yaml diff --git a/components/sample/R_script/component.yaml b/components/sample/R_script/component.yaml new file mode 100644 index 0000000000..ba9a3805dd --- /dev/null +++ b/components/sample/R_script/component.yaml @@ -0,0 +1,39 @@ +name: Filter text +inputs: +- {name: Text} +- {name: Pattern, default: '.*'} +outputs: +- {name: Filtered text} +metadata: + annotations: + author: Alexey Volkov +implementation: + container: + image: r-base:4.0.2 + command: + - Rscript + - -e + - | + args <- commandArgs(trailingOnly = TRUE) + textPath <- args[1] + pattern <- args[2] + filteredTextPath <- args[3] + + dir.create(dirname(filteredTextPath), showWarnings = FALSE, recursive = TRUE) + + inputFile = file(textPath, "r") + outputFile = file(filteredTextPath, "w") + while ( TRUE ) { + lines = readLines(inputFile, n = 1) + if ( length(lines) == 0 ) { + break + } + if ( grepl(pattern = pattern, lines) ) { + writeLines(lines, outputFile) + } + } + close(outputFile) + close(inputFile) + - {inputPath: Text} + - {inputValue: Pattern} + - {outputPath: Filtered text}