piston/runtimes/rscript.nix

60 lines
1.3 KiB
Nix
Raw Permalink Normal View History

2022-02-07 02:38:30 +01:00
{pkgs, piston, ...}:
let
2022-02-07 06:08:05 +01:00
pkg = pkgs.R;
2022-02-07 02:38:30 +01:00
in piston.mkRuntime {
language = "rscript";
2022-02-07 06:08:05 +01:00
version = pkg.version;
2022-02-07 02:38:30 +01:00
aliases = [
"r"
];
run = ''
${pkg}/bin/Rscript "$@"
'';
tests = [
# test different extension
(piston.mkTest {
files = {
"file.code" = ''
cat('OK')
'';
};
args = [];
stdin = "";
packages = [];
main = "file.code";
})
# test argv
(piston.mkTest {
files = {
"test.r" = ''
cat(commandArgs(trailingOnly=TRUE))
'';
};
args = ["OK"];
stdin = "";
packages = [];
main = "test.r";
})
# test stdin
(piston.mkTest {
files = {
"test.r" = ''
f <- file("stdin")
open(f)
while(length(line <- readLines(f,n=1)) > 0) {
write(line, stderr())
cat(line)
}
'';
};
args = [];
stdin = "OK";
packages = [];
main = "test.r";
})
];
2022-02-07 06:08:05 +01:00
}