On Windows, ‘env’ is only supported for commands such as ‘R’ and
‘make’ which accept environment variables on their command line.
So I suppose that would be tricky.
The basic issue is that on Unix-alikes, system2 constructs a command like
FOO=bar cmd args
and passes that to sh via system(). On windoes, system() does not call sh, so
system2() does (effectively)
cmd FOO=bar args
and hopes that cmd knows what to do with the env setting.
-pd
> On 19 Mar 2019, at 11:09 , Gábor Csárdi <[email protected]> wrote:
>
> On Tue, Mar 19, 2019 at 9:59 AM peter dalgaard <[email protected]> wrote:
> [...]
>> What you need is something like (NB: single quotes!)
>>> system2("sh", env = c("VAR='Hello World'"), args = c("-c 'echo $VAR'"))
>> Hello World
>
> Just out of curiosity, do you think it is possible to make this
> portable, assuming sh is available? On Windows it gives
>
>> system2("sh", env = c("VAR='Hello World'"), args = c("-c 'echo $VAR'"))
> /rtools34/bin/sh: VAR=Hello World: No such file or directory
> Warning message:
> running command '"sh" VAR='Hello World' -c 'echo $VAR'' had status 127
>
> G.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [email protected] Priv: [email protected]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel