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.bre...@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@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel