Greetings - I have a quick question that I hope someone will have a quick answer. I have tried to use the R function "system" with the MS-DOS command "type" to display the full content of a text file. But it always returns with a message saying the text file is not found. I could accomplish the same task with the "cat" command which is one of the unix-like commands that I have installed on my windows machine. But I would like to know how it would work with the "type" command. Here is what I have tried:> zz<-file("d:/work/test/test.txt", "w") > cat("this is a test\n", file=zz) > close(zz) > system("cat test.txt", show.output.on.console=T)this is a test> system("type test.txt", show.output.on.console=T)test.txt not found>Thanks much for any help that you could offer. Best, Xiao Chen Statistical Consulting Group UCLA Academic Technology Services http://www.ats.ucla.edu/stat/
Vladimir Eremeev
2007-Jan-31 11:36 UTC
[R] help with function "system" and MS-DOS command TYPE
Chen, Xiao wrote:> > Greetings - > > I have a quick question that I hope someone will have a quick answer. I > have tried to use the R function "system" with the MS-DOS command "type" > to display the full content of a text file. But it always returns with a > message saying the text file is not found. I could accomplish the same > task with the "cat" command which is one of the unix-like commands that > I have installed on my windows machine. But I would like to know how it > would work with the "type" command. > > Here is what I have tried: > >> zz<-file("d:/work/test/test.txt", "w") >> cat("this is a test\n", file=zz) >> close(zz) >> system("cat test.txt", show.output.on.console=T) > this is a test >> system("type test.txt", show.output.on.console=T) > test.txt not found >type is an internal command, rather than an executable file use system("cmd /c type test.txt", show.output.on.console=T) or system("command /c type test.txt", show.output.on.console=T) -- View this message in context: http://www.nabble.com/-R--help-with-function-%22system%22-and-MS-DOS-command-TYPE-tf3146629.html#a8727428 Sent from the R help mailing list archive at Nabble.com.
Try 'file.show' On 1/30/07, Chen, Xiao <jingy1 at ucla.edu> wrote:> Greetings - > > I have a quick question that I hope someone will have a quick answer. I > have tried to use the R function "system" with the MS-DOS command "type" > to display the full content of a text file. But it always returns with a > message saying the text file is not found. I could accomplish the same > task with the "cat" command which is one of the unix-like commands that > I have installed on my windows machine. But I would like to know how it > would work with the "type" command. > > Here is what I have tried: > > > zz<-file("d:/work/test/test.txt", "w") > > cat("this is a test\n", file=zz) > > close(zz) > > system("cat test.txt", show.output.on.console=T) > this is a test > > system("type test.txt", show.output.on.console=T) > test.txt not found > > > > > Thanks much for any help that you could offer. > > Best, > > Xiao Chen > Statistical Consulting Group > UCLA Academic Technology Services > http://www.ats.ucla.edu/stat/ > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Prof Brian Ripley
2007-Jan-31 13:57 UTC
[R] help with function "system" and MS-DOS command TYPE
On Wed, 31 Jan 2007, Vladimir Eremeev wrote:> Chen, Xiao wrote: >> >> Greetings - >> >> I have a quick question that I hope someone will have a quick answer. I >> have tried to use the R function "system" with the MS-DOS command "type" >> to display the full content of a text file. But it always returns with a >> message saying the text file is not found. I could accomplish the same >> task with the "cat" command which is one of the unix-like commands that >> I have installed on my windows machine. But I would like to know how it >> would work with the "type" command. >> >> Here is what I have tried: >> >>> zz<-file("d:/work/test/test.txt", "w") >>> cat("this is a test\n", file=zz) >>> close(zz) >>> system("cat test.txt", show.output.on.console=T) >> this is a test >>> system("type test.txt", show.output.on.console=T) >> test.txt not found >> > > type is an internal command, rather than an executable file > > use > system("cmd /c type test.txt", show.output.on.console=T) > or > system("command /c type test.txt", show.output.on.console=T)or use the user-friendly version shell(), as it says on the help page for system() (together with a portable version of the above). Please can people who answer questions do their homework as the posting guide requests, and point to the definitive documentation. The archives of these lists are a public resource, and often searched to pick up pieces of misinformation. -- 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
Dear R-Help, Thanks much. I have received very good advice from a couple of experts. R-help is just wonderful! I have combined all the solutions that I got and they are shown below: zz<-file("d:/work/test/test.txt", "w") cat("this is a test\n", file=zz) close(zz) setwd("d:/work/test") shell("type test.txt") system("cat test.txt", show.output.on.console=T) file.show("d:/work/test/test.txt") #opens a new window file.show("d:/work/test/test.txt", pager="console") #displays on console Thanks again for all the help. Best regards, Xiao Chen Statistical Consulting Group UCLA Academic Technology Services http://www.ats.ucla.edu/stat/ -----Original Message----- From: Chen, Xiao Sent: Tuesday, January 30, 2007 8:23 PM To: 'r-help at stat.math.ethz.ch' Subject: help with function "system" and MS-DOS command TYPE Greetings - I have a quick question that I hope someone will have a quick answer. I have tried to use the R function "system" with the MS-DOS command "type" to display the full content of a text file. But it always returns with a message saying the text file is not found. I could accomplish the same task with the "cat" command which is one of the unix-like commands that I have installed on my windows machine. But I would like to know how it would work with the "type" command. Here is what I have tried:> zz<-file("d:/work/test/test.txt", "w") > cat("this is a test\n", file=zz) > close(zz) > system("cat test.txt", show.output.on.console=T)this is a test> system("type test.txt", show.output.on.console=T)test.txt not found>Thanks much for any help that you could offer. Best, Xiao Chen Statistical Consulting Group UCLA Academic Technology Services http://www.ats.ucla.edu/stat/
Maybe Matching Threads
- Como se hace el operador "o" (OR) para seleccionar dos o mas niveles de un vector ?
- R vs SAS and HLM on multilevel analysis- basic question
- poisson regression with robust error variance ('eyestudy
- Comparing Negative Binomial Regression in Stata and R. Constants differ?
- add spline to longitudinal data - preferably similar to SAS's 'I=SM50S' routine