From 846269cbb32443677e16571deadcbf05e03531e8 Mon Sep 17 00:00:00 2001 From: "David J. Malan" Date: Wed, 31 Jan 2024 09:05:52 -0500 Subject: [PATCH] added support for stdin, command-line args to R --- opt/cs50/bin/R | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/opt/cs50/bin/R b/opt/cs50/bin/R index 5362c6b..657783d 100755 --- a/opt/cs50/bin/R +++ b/opt/cs50/bin/R @@ -1,11 +1,23 @@ #!/bin/bash -IMAGE="rocker/r-ver" - -docker run \ - --interactive \ - --rm \ - --tty \ - --volume "$LOCAL_WORKSPACE_FOLDER":/mnt \ - --workdir /mnt \ - "$IMAGE" +IMAGE=rocker/r-ver + +options=( + --interactive + --rm + --volume "$LOCAL_WORKSPACE_FOLDER":/mnt + --workdir /mnt + $IMAGE + R + "$@" +) + +# If TTY +if [[ -t 0 ]]; then + options=(--tty "${options[@]}") + docker run "${options[@]}" + +# If pipe +else + cat | docker run "${options[@]}" +fi