Hello! with the R system command I would like to call a perl script which needs an input directory and an output directory in form of a path. When I put in the path directly it works. The script line looks as follows: system("perl '../path1' '../path2' '../path3'") If I store the path in a variable/object and call the perl script again it does not run and I don't know how to overcome that issue. p1 <- "../path1" p2 <- "../path2" p3 <- "../path3" system("perl p1 p2 p3") I also tried: system("perl 'p1' 'p2' 'p3'") Can anyone help? Best, syrvn -- View this message in context: http://r.789695.n4.nabble.com/R-system-command-does-not-work-with-objects-variables-tp3762544p3762544.html Sent from the R help mailing list archive at Nabble.com.
Prof Brian Ripley
2011-Aug-23 12:16 UTC
[R] R system command does not work with objects/variables
See ?paste or use system2("perl", shQuote(c(p1, p2, p3))) On Tue, 23 Aug 2011, syrvn wrote:> Hello! > > with the R system command I would like to call a perl script which needs an > input directory and an output directory in form of a path. When I put in the > path directly it works. The script line looks as follows: > > system("perl '../path1' '../path2' '../path3'") > > If I store the path in a variable/object and call the perl script again it > does not run and I don't know how to overcome that issue. > > p1 <- "../path1" > p2 <- "../path2" > p3 <- "../path3" > > system("perl p1 p2 p3") > > I also tried: > > system("perl 'p1' 'p2' 'p3'") > > Can anyone help? > > Best, > syrvn > > -- > View this message in context: http://r.789695.n4.nabble.com/R-system-command-does-not-work-with-objects-variables-tp3762544p3762544.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Hi, it works great with the paste command! thanks a lot! Best, syrvn -- View this message in context: http://r.789695.n4.nabble.com/R-system-command-does-not-work-with-objects-variables-tp3762544p3762583.html Sent from the R help mailing list archive at Nabble.com.
Johann Hibschman
2011-Aug-23 13:06 UTC
[R] R system command does not work with objects/variables
syrvn <mentor_ at gmx.net> writes:> If I store the path in a variable/object and call the perl script again it > does not run and I don't know how to overcome that issue. > > p1 <- "../path1" > p2 <- "../path2" > p3 <- "../path3" > > system("perl p1 p2 p3")You want something like: system(paste("perl", p1, p2, p3")) Strings don't do interpolation by themselves; you need to tell R, via the "paste" function, that you want to concatenate the strings together. -Johann