[Rd] Possibly broken system2 env-option
Henning Bredel
h@brede| @end|ng |rom gmx@de
Tue Mar 19 12:33:46 CET 2019
Okay, thanks for clarification.
On 3/19/19 10:51 AM, peter dalgaard wrote:
> You are using it wrong. It wants strings of the form "name=value", not a character vector with names as labels. So this is closer to the mark:
>
>> system2("echo", env = c("VAR='Hello World'"), args = c("$VAR"))
>
>>
>
> However, as you see it doesn't work as intended. The problem is that the $-substitution refers to the environment of the shell executing the command. I.e. this does not work from a terminal command line either:
>
> pd$ VAR="foo" echo $VAR
>
> pd$
>
> Or even
>
> pd$ VAR="bar"
> pd$ VAR="foo" echo $VAR
> bar
>
> What you need is something like (NB: single quotes!)
>
> pd$ VAR="foo" sh -c 'echo $VAR'
> foo
>
> So:
>
>> system2("sh", env = c("VAR='Hello World'"), args = c("-c 'echo $VAR'"))
> Hello World
>
> -pd
>
>> On 18 Mar 2019, at 17:28 , Henning Bredel <h.bredel using gmx.de> wrote:
>>
>> Hey all,
>>
>> what is wrong with this command:
>>
>> system2("echo", env = c(VAR = "Hello World"), args = c("$VAR"))
>>
>> I am a bit confused, as help("system2") writes about the env option:
>>
>>> character vector of name=value strings to set environment variables.
>>
>> Is this option buggy, or am I using it just wrong?
>>
>> Thanks for your help
>>
>> Henning
>>
>> ______________________________________________
>> R-devel using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list