How can I best achieve the following (works in Splus): filenames <- dos("dir *.sasb7dat /b") What I am asking, more generically, is: how can I capture the output of a DOS command in R? I have tried using system("COMMAND.COM /c dir /b", intern=T, show.output.on.console=T) where intern: a logical, indicates whether to make the output of the command an R object. but it makes no useful difference:> system("COMMAND.COM /c dir /b", intern=T, show.output.on.console=T)character(0)> print(system("COMMAND.COM /c dir /b", intern=F,show.output.on.console=T)) [1] 0 In both cases here a DOS window opens and lists a couple of hundred files, before giving the above output. I am also a bit baffled by "show.output.on.console" whose only effect seems to be on whether the DOS screen opens for one millisecond or for one second. It does not, per help, "show the output of the command on the R console". Incidentally I can answer the problem at hand using the following workaround (but what I'm after is a more generic solution): shell("dir D:\\tmp\\*.sasb7dat /b > D:\\tmp\\Paula\\dirlist.lst") dataset.names <- scan("D:\\tmp\\dirlist.lst", what="", sep="\n") TIA SF Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
"Simon Fear" <Simon.Fear at synequanon.com> writes:> > system("COMMAND.COM /c dir /b", intern=T, show.output.on.console=T) > character(0) > > print(system("COMMAND.COM /c dir /b", intern=F, > show.output.on.console=T)) > [1] 0 > > In both cases here a DOS window opens and lists a couple of hundred > files, > before giving the above output.Does it help if you drop the "COMMAND.COM /c" bit?? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Simon Fear wrote:> How can I best achieve the following (works in Splus): > > filenames <- dos("dir *.sasb7dat /b") > > What I am asking, more generically, is: how can I capture the output of > a > DOS command in R? > > I have tried using > > system("COMMAND.COM /c dir /b", intern=T, show.output.on.console=T) > > where > > intern: a logical, indicates whether to make the output of the > command an R object. > > but it makes no useful difference: > > >>system("COMMAND.COM /c dir /b", intern=T, show.output.on.console=T) > > character(0) > >>print(system("COMMAND.COM /c dir /b", intern=F, > > show.output.on.console=T)) > [1] 0 > > In both cases here a DOS window opens and lists a couple of hundred > files, > before giving the above output. > > I am also a bit baffled by "show.output.on.console" whose only effect > seems > to be on whether the DOS screen opens for one millisecond or for one > second. > It does not, per help, "show the output of the command on the R > console". > > Incidentally I can answer the problem at hand using the following > workaround > (but what I'm after is a more generic solution): > > shell("dir D:\\tmp\\*.sasb7dat /b > D:\\tmp\\Paula\\dirlist.lst") > dataset.names <- scan("D:\\tmp\\dirlist.lst", what="", sep="\n")So you almost got it, just read ?shell carefully enough: filenames <- shell("dir D:\\tmp\\*.sasb7dat /b", intern = TRUE) or even better in this case: filenames <- list.files("d:/tmp", pattern = "sasb7dat") Uwe Ligges> TIA > SF > > > Simon Fear > Senior Statistician > Syne qua non Ltd > Tel: +44 (0) 1379 644449 > Fax: +44 (0) 1379 644445 > email: Simon.Fear at synequanon.com > web: http://www.synequanon.com > > Number of attachments included with this message: 0 > > This message (and any associated files) is confidential and\...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Peter, thanks for quick reply, but I can't drop it:> system("dir /b", intern=T, show.output.on.console=T)Error in system("dir /b", intern = T, show.output.on.console = T) : dir not found> From: Peter Dalgaard BSA [mailto:p.dalgaard at biostat.ku.dk] > snip <> Does it help if you drop the "COMMAND.COM /c" bit??Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
Uwe, you suggest> So you almost got it, just read ?shell carefully enough: > > filenames <- shell("dir D:\\tmp\\*.sasb7dat /b", intern = TRUE) >Unfortunately, this does not work and is why I wrote to Rhelp (OK I used system instead of shell, but I tried shell first); here filenames is assigned character(0) even though the dir output is not empty. Believe me I did read ?shell many times before I wrote: but I am reporting that shell does not do what ?shell says it should.> or even better in this case: > > filenames <- list.files("d:/tmp", pattern = "sasb7dat") >THANK YOU! I'm always forgetting about file.* and friends. Platform independent too. Still leaves me asking the bigger question though: how do I capture DOS command output in general? Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
Prof Brian Ripley writes:> > If you insist on using a long-obselete OS, please help us continue ot > support it by supplying patches and workarounds. I think we (like > Microsoft) are going to have to think seriously about withdrawing > support > from non-NT-based versions of Windows fairly soon. >Believe me, using Win98 is NOT my choice. I would only ever use Unix/Linux. Are there other statisticians similarly limited? I am already sticking my neck out quite a lot using R in an industry obsessed with SAS. If I tell IT I'm going to use a nonstandard shell, emacs, ess, bash, and CygWin as well as R they'll probably revoke my username. Still, I for one can understand withdrawing support for old OSs and if I have to stick with 1.7.1 as being the last version to work with Win98 so be it - it as, after all, as is, the most amazing piece of software any statistician could have wished for. Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
>Believe me, using Win98 is NOT my choice. I would only ever use >Unix/Linux. >Are there other statisticians similarly limited?Like Simon I am very often limited with choice of software and OS when working for clients. I've been waiting for about 5 months to get an editor installed on my machine. I have requested emacs but will settle for anything but the current choice - MS Notepad (I'm serious). The first time we requested an R installation we waited about 3 or 4 months (thanks to constant pressure from our statistical guru). To get the latest version of R we had another 3 or 4 months wait! Then when we finally got it (version 1.6.2) then next version had been released a week earlier (1.7.0 - I think)! Very frustrating! As you can imagine every time I read "Please upgrade to version 1.7.x" - I just wish it was so simple! Best regards, Saghir --------------------------------------------------------- Legal Notice: This electronic mail and its attachments are i...{{dropped}}
Why should it take months to get these installed ? Both R and emacs are simple and free to install. If high speed internet access is a problem, you can always download these from some Internet Caf? or a friend, burn it into CD and install onto the machines. If you have red tapes on installing softwares, then good luck. I suppose they would not be so happy purchasing SPLUS than installing free softwares for you. -----Original Message----- From: Bashir Saghir (Aztek Global) [mailto:Saghir.Bashir at UCB-Group.com] Sent: Wednesday, August 13, 2003 6:02 PM To: 'Simon Fear'; Prof Brian Ripley; Uwe Ligges Cc: r-help at stat.math.ethz.ch Subject: RE: [R] capturing output from Win 98 shell>Believe me, using Win98 is NOT my choice. I would only ever use >Unix/Linux. Are there other statisticians similarly limited?Like Simon I am very often limited with choice of software and OS when working for clients. I've been waiting for about 5 months to get an editor installed on my machine. I have requested emacs but will settle for anything but the current choice - MS Notepad (I'm serious). The first time we requested an R installation we waited about 3 or 4 months (thanks to constant pressure from our statistical guru). To get the latest version of R we had another 3 or 4 months wait! Then when we finally got it (version 1.6.2) then next version had been released a week earlier (1.7.0 - I think)! Very frustrating! As you can imagine every time I read "Please upgrade to version 1.7.x" - I just wish it was so simple! Best regards, Saghir --------------------------------------------------------- Legal Notice: This electronic mail and its attachments are i...{{dropped}} ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Actually, if you read your university's rules about use of IT facilities, I am willing to bet they expressly forbid the (down)loading and use of software without permission. This was certainly in the small print in all the UK universities where I had a .ac.uk account. There were some relaxations for staff. The difference is that within academia this rule is universally ignored, whereas in the .com world it would cost you your job (and your company a potential audit failure). Anyway, can I suggest we drop this thread from the list now as having drifted too far off-topic? (except to forestall questions like "why are you still using version 0.9 - please update", which should be "please update - oh sorry, now I see your .com address - my sympathies, please try again using Windows 3.1").> -----Original Message----- > From: Adaikalavan Ramasamy [mailto:gisar at nus.edu.sg] > > Why should it take months to get these installed ? >Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}