Dear All: Maybe it is a too basic question, but I don't how to find the answer. Sorry for that. What I want to do is call a shell command, which will provide two numbers, and assign those numbers to a vector. For example: The following command: $mxresult.sh ABC.mx mxresult.sh is a script written by myself and ABC.mx is a Mx script. I can get two numbers, 126.128 and 29, with this command. Is there any way to do it like this: c <- somefunction("mxresult.sh ABC.mx") Or is their any other way to fulfill the function? Thanks in advance! Best washes, Wei-Wei
Guo Wei-Wei wrote:> Dear All: > > Maybe it is a too basic question, but I don't how to find the answer. > Sorry for that. > > What I want to do is call a shell command, which will provide two > numbers, and assign those numbers to a vector. For example: > > The following command: > > $mxresult.sh ABC.mx > > mxresult.sh is a script written by myself and ABC.mx is a Mx script. > I can get two numbers, 126.128 and 29, with this command. > > Is there any way to do it like this: > > c <- somefunction("mxresult.sh ABC.mx") > > Or is their any other way to fulfill the function? >txt <- system(""mxresult.sh ABC.mx", intern=TRUE) is the first step. Then you need to get the numbers using either a scan() on a textConnection (see its help page) or something like mynum <- as.numeric(strsplit(txt, " *")[[1]])> Thanks in advance! > > Best washes, > Wei-Wei > > ______________________________________________ > 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. >
?system. Cheers, Andrew On Tue, Feb 27, 2007 at 02:05:09PM +0800, Guo Wei-Wei wrote:> Dear All: > > Maybe it is a too basic question, but I don't how to find the answer. > Sorry for that. > > What I want to do is call a shell command, which will provide two > numbers, and assign those numbers to a vector. For example: > > The following command: > > $mxresult.sh ABC.mx > > mxresult.sh is a script written by myself and ABC.mx is a Mx script. > I can get two numbers, 126.128 and 29, with this command. > > Is there any way to do it like this: > > c <- somefunction("mxresult.sh ABC.mx") > > Or is their any other way to fulfill the function? > > Thanks in advance! > > Best washes, > Wei-Wei > > ______________________________________________ > 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.-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/