Skip to content
Back to formatted view

Raw Message

Message-ID: <CANVKczOSdPP1_8hLFU4BFzOADgvmYFHLMzCxd6_A62SNbKSLnQ@mail.gmail.com>
Date: 2012-10-30T16:02:31Z
From: Barry Rowlingson
Subject: export variable from bash to R
In-Reply-To: <48a4dd1aa2dc4a0b88608a52319de663@EX-0-HT0.lancs.local>

On Tue, Oct 30, 2012 at 2:03 PM, sophie <melanie.bieli at bluewin.ch> wrote:
> Hi Barry
>
> Thank you very much for your reply. I changed my scripts according to your
> suggestions - this is how they look now:
>
> #!/bin/bash
>
> VARIABLES=( a b c d )
>
> for i in ${VARIABLES[@]}; do
>       export VARIABLENAME=$i
>       Rscript -e 'source("myscript.R")'
> done
>
> and in the R program, I used
> args <- Sys.getenv("VARIABLENAME")  instead of args <- commandArgs(TRUE)
>
> But when I add the "R --slave", the program hangs, so I left it out (you
> said it was just to cut out the startup messages, so I assumed it shouldn't
> really matter).

 It didn't hang, it was probably sitting there waiting for you to say
q() - I was just using it interactively.

> It's still not working, though. There is no error message,
> but the R program still doesn't seem to be executed (@Krzysztof: The R
> program makes plots - since these plots are not produced,  I figured that
> something with the call of myscript.R is not working)
>
> Any ideas or suggestions?

 Does it produce any printed output? Can you add some print statements
to see where it gets to?

$ cat myscript.R
print("Hello world")
$ Rscript -e 'source("myscript.R")'
[1] "Hello world"

 - here at least I know its finding the right script.

Barry