From h@brede| @end|ng |rom gmx@de  Tue Mar 19 12:33:46 2019
From: h@brede| @end|ng |rom gmx@de (Henning Bredel)
Date: Tue, 19 Mar 2019 12:33:46 +0100
Subject: [Rd] Possibly broken system2 env-option
In-Reply-To: <3244E2B3-3E44-4469-919B-4E5768F06F23@gmail.com>
References: <f38d1b55-c8f8-dbe4-94c4-bf15bb32c052@gmx.de>
 <3244E2B3-3E44-4469-919B-4E5768F06F23@gmail.com>
Message-ID: <8ec75b7c-722a-3d03-5976-db3e9b5e69fb@gmx.de>

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 at 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 at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Possibly broken system2 env-option
Henning Bredel