[R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Ronaldo Reis Junior
Hi,

It is possible to use a shell command inside a R script?

I'm write a R script and I like to put somes shell commands inside to R. 
Somethink like: convert fig01.png fig01.xpm or sed ..., etc.

It is possible? How?

Thanks
Ronaldo
-- 
Acalme-se, são somente 0's e 1's
--
 Prof. Ronaldo Reis Júnior
|  .''`. UNIMONTES/Depto. Biologia Geral/Lab. de Ecologia
| : :'  : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia
| `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil
|   `- Fone: (38) 3229-8187 | [EMAIL PROTECTED] | [EMAIL PROTECTED]
| http://www.ppgcb.unimontes.br/ | ICQ#: 5692561 | LinuxUser#: 205366

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Alberto Monteiro
Ronaldo Reis Junior wrote:
 
 It is possible to use a shell command inside a R script?
 
 I'm write a R script and I like to put somes shell commands inside 
 to R. Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 
 It is possible? How?
 
?system

BTW, I found that using things directly in R is _much_
slower than creating a batch file and then running it.

For example, I had a directory with misnamed mp3 files,
and I wanted to use R to rename and copy them
to another directory. I tried to use file.copy, but it 
took too much time. Writing a batch file and then running
it was much faster.

Alberto Monteiro

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Henrique Dallazuanna
Hi,

see ?system

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

On 24/08/07, Ronaldo Reis Junior [EMAIL PROTECTED] wrote:

 Hi,

 It is possible to use a shell command inside a R script?

 I'm write a R script and I like to put somes shell commands inside to R.
 Somethink like: convert fig01.png fig01.xpm or sed ..., etc.

 It is possible? How?

 Thanks
 Ronaldo
 --
 Acalme-se, são somente 0's e 1's
 --
  Prof. Ronaldo Reis Júnior
 |  .''`. UNIMONTES/Depto. Biologia Geral/Lab. de Ecologia
 | : :'  : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia
 | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil
 |   `- Fone: (38) 3229-8187 | [EMAIL PROTECTED] |
 [EMAIL PROTECTED]
 | http://www.ppgcb.unimontes.br/ | ICQ#: 5692561 | LinuxUser#: 205366

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
 Hi,
 
 It is possible to use a shell command inside a R script?
 
 I'm write a R script and I like to put somes shell commands inside to R. 
 Somethink like: convert fig01.png fig01.xpm or sed ..., etc.

The details and available functions depend on the platform, but you want 
to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
Windows; on Unix-alikes, you probably won't have the latter two.)

Duncan Murdoch

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 8:05 AM, Alberto Monteiro wrote:
 Ronaldo Reis Junior wrote:
 
 It is possible to use a shell command inside a R script?
 
 I'm write a R script and I like to put somes shell commands inside 
 to R. Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 
 It is possible? How?
 
 ?system
 
 BTW, I found that using things directly in R is _much_
 slower than creating a batch file and then running it.
 
 For example, I had a directory with misnamed mp3 files,
 and I wanted to use R to rename and copy them
 to another directory. I tried to use file.copy, but it 
 took too much time. Writing a batch file and then running
 it was much faster.

Since you say batch file I assume you're on Windows.  If that's the 
case, then file.rename() can rename and move a file to a new directory, 
as long as it's on the same drive.  That should be as quick as a batch file.

Duncan Murdoch

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Gabor Grothendieck
What OS was that on?

On 8/24/07, Alberto Monteiro [EMAIL PROTECTED] wrote:
 Ronaldo Reis Junior wrote:
 
  It is possible to use a shell command inside a R script?
 
  I'm write a R script and I like to put somes shell commands inside
  to R. Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 
  It is possible? How?
 
 ?system

 BTW, I found that using things directly in R is _much_
 slower than creating a batch file and then running it.

 For example, I had a directory with misnamed mp3 files,
 and I wanted to use R to rename and copy them
 to another directory. I tried to use file.copy, but it
 took too much time. Writing a batch file and then running
 it was much faster.

 Alberto Monteiro

 __
 R-help@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.


__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Alberto Monteiro

Gabor Grothendieck wrote:

 What OS was that on?

I suppose you are asking me :-)
 
 BTW, I found that using things directly in R is _much_
 slower than creating a batch file and then running it.

 For example, I had a directory with misnamed mp3 files,
 and I wanted to use R to rename and copy them
 to another directory. I tried to use file.copy, but it
 took too much time. Writing a batch file and then running
 it was much faster.

I was Windows, of course. In Linux, I would use a one-line
script with find, mv, sed, etc.

If you want to test, do this:

# create subdiretory source_dir with 800 files
# (for simplicity's sake, all files with decent names: no
# spaces, no non-ascii characters, etc)
# create empty subdiretory dest1_dir
# create empty subdiretory dest2_dir
#

arr - list.files(source_dir)
t0 - Sys.time()
# 1st test: slow
for (x in arr)
  file.copy(paste(source_dir/, x, sep=), dest1_dir)
t1 - Sys.time()
t1 - t0
# 2nd test: fast
sink(batch_file.bat)
for (x in arr)
  cat(copy source_dir\\, x,  dest2_dir\\\n, sep=)
sink()
system(batch_file.bat)
t2 - Sys.time()
t2 - t1

Hmmm Interesting... I did this test with 47 files, and I got:

t1 - t0
Time difference of 11.439 secs

t2 - t1
Time difference of 11.969 secs

Oops...

Alberto Monteiro

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Dirk Eddelbuettel
On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
 On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
  Hi,
  
  It is possible to use a shell command inside a R script?
  
  I'm write a R script and I like to put somes shell commands inside to R. 
  Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 
 The details and available functions depend on the platform, but you want 
 to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
 Windows; on Unix-alikes, you probably won't have the latter two.)

Don't forget pipes. 

R's ability to consistently work on connections that may be local
files, remotes files, program output, ... is a true treasure (and
thanks and credits to, I believe, Brian Ripley to make it so).

Eg you can do this 

  OD - read.table(pipe(links -dump http://cran.r-project.org/src/contrib/ | 
awk '/tar.gz/ {print $3, $4}'), header=FALSE, col.names=c(file, date))

to get files and dates of files on CRAN.   

As I recall, this also works on that other operating system, provided
you do all the legwork of installing other tools, setting PATHs etc
to provide what works out of the box on the supposedly unfriendlier OS.

Dirk

-- 
Three out of two people have difficulties with fractions.

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
 On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
 On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
  Hi,
  
  It is possible to use a shell command inside a R script?
  
  I'm write a R script and I like to put somes shell commands inside to R. 
  Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 
 The details and available functions depend on the platform, but you want 
 to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
 Windows; on Unix-alikes, you probably won't have the latter two.)
 
 Don't forget pipes. 
 
 R's ability to consistently work on connections that may be local
 files, remotes files, program output, ... is a true treasure (and
 thanks and credits to, I believe, Brian Ripley to make it so).
 
 Eg you can do this 
 
   OD - read.table(pipe(links -dump http://cran.r-project.org/src/contrib/ | 
 awk '/tar.gz/ {print $3, $4}'), header=FALSE, col.names=c(file, date))
 
 to get files and dates of files on CRAN.   
 
 As I recall, this also works on that other operating system, provided
 you do all the legwork of installing other tools, setting PATHs etc
 to provide what works out of the box on the supposedly unfriendlier OS.

The pipe command you list doesn't work in Windows.  I'd guess this is 
because the pipe syntax | within the command is unsupported:  it tries 
to execute links, with the rest of the line passed as arguments.  But 
I haven't traced through to check on this.

Duncan Murdoch

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Dirk Eddelbuettel
On Fri, Aug 24, 2007 at 10:57:46AM -0400, Duncan Murdoch wrote:
 On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
 On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
 On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
  Hi,
   It is possible to use a shell command inside a R script?
   I'm write a R script and I like to put somes shell commands inside to 
 R.  Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 The details and available functions depend on the platform, but you want 
 to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
 Windows; on Unix-alikes, you probably won't have the latter two.)
 Don't forget pipes. R's ability to consistently work on connections that 
 may be local
 files, remotes files, program output, ... is a true treasure (and
 thanks and credits to, I believe, Brian Ripley to make it so).
 Eg you can do this   OD - read.table(pipe(links -dump 
 http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, $4}'), 
 header=FALSE, col.names=c(file, date))
 to get files and dates of files on CRAN.   As I recall, this also works on 
 that other operating system, provided
 you do all the legwork of installing other tools, setting PATHs etc
 to provide what works out of the box on the supposedly unfriendlier OS.

 The pipe command you list doesn't work in Windows.  I'd guess this is 
 because the pipe syntax | within the command is unsupported:  it tries to 
 execute links, with the rest of the line passed as arguments.  But I 
 haven't traced through to check on this.

Hm, wishful thinking must have gotten the better of me then. Sorry for
spreading misinformation about the capabilities of that other OS.

Dirk

-- 
Three out of two people have difficulties with fractions.

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Gabor Grothendieck
On 8/24/07, Dirk Eddelbuettel [EMAIL PROTECTED] wrote:
 On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
  On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
   Hi,
  
   It is possible to use a shell command inside a R script?
  
   I'm write a R script and I like to put somes shell commands inside to R.
   Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 
  The details and available functions depend on the platform, but you want
  to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in
  Windows; on Unix-alikes, you probably won't have the latter two.)

 Don't forget pipes.

 R's ability to consistently work on connections that may be local
 files, remotes files, program output, ... is a true treasure (and
 thanks and credits to, I believe, Brian Ripley to make it so).

 Eg you can do this

  OD - read.table(pipe(links -dump http://cran.r-project.org/src/contrib/ | 
 awk '/tar.gz/ {print $3, $4}'), header=FALSE, col.names=c(file, date))

 to get files and dates of files on CRAN.

 As I recall, this also works on that other operating system, provided
 you do all the legwork of installing other tools, setting PATHs etc
 to provide what works out of the box on the supposedly unfriendlier OS.


Or commonly we can just do it entirely within R.  In the example discussed
we read in the lines, grep out the tar.gz lines, split each line into
fields and
select the desired columns, delete the junk and reformat it all into a
data frame:

 Lines - readLines(http://cran.r-project.org/src/contrib/;)
 tar.gz.Lines - grep(tar.gz, Lines, value = TRUE)
 raw.fields - do.call(rbind, strsplit(tar.gz.Lines, /td))[, 2:3]
 mat - apply(raw.fields, 2, gsub, pattern = /a|.*\| *$, replacement = 
 )
 DF - data.frame(file = mat[,1],
+   date = strptime(mat[,2], %d-%b-%Y %H:%M),
+   stringsAsFactors = FALSE)
 head(DF)
 filedate
1 ADaCGH_1.3-1.tar.gz 2007-05-14 12:04:00
2  AIS_1.0.tar.gz 2007-07-31 16:38:00
3 AMORE_0.2-10.tar.gz 2007-04-11 10:17:00
4   ARES_1.2-2.tar.gz 2007-03-19 20:53:00
5 AcceptanceSampling_0.1-1.tar.gz 2007-07-07 20:46:00
6   AdaptFit_0.2-1.tar.gz 2007-08-04 09:51:00

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Gabor Grothendieck
On 8/24/07, Dirk Eddelbuettel [EMAIL PROTECTED] wrote:
 On Fri, Aug 24, 2007 at 10:57:46AM -0400, Duncan Murdoch wrote:
  On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
  On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
  On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
   Hi,
It is possible to use a shell command inside a R script?
I'm write a R script and I like to put somes shell commands inside to
  R.  Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
  The details and available functions depend on the platform, but you want
  to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in
  Windows; on Unix-alikes, you probably won't have the latter two.)
  Don't forget pipes. R's ability to consistently work on connections that
  may be local
  files, remotes files, program output, ... is a true treasure (and
  thanks and credits to, I believe, Brian Ripley to make it so).
  Eg you can do this   OD - read.table(pipe(links -dump
  http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, $4}'),
  header=FALSE, col.names=c(file, date))
  to get files and dates of files on CRAN.   As I recall, this also works on
  that other operating system, provided
  you do all the legwork of installing other tools, setting PATHs etc
  to provide what works out of the box on the supposedly unfriendlier OS.
 
  The pipe command you list doesn't work in Windows.  I'd guess this is
  because the pipe syntax | within the command is unsupported:  it tries to
  execute links, with the rest of the line passed as arguments.  But I
  haven't traced through to check on this.

 Hm, wishful thinking must have gotten the better of me then. Sorry for
 spreading misinformation about the capabilities of that other OS.

This works for me on Windows:

 tab - read.table(pipe(lynx --nolist --dump 
 http://cran.r-project.org/src/contrib/ | findstr tar.gz), as.is = TRUE)
 head(tab[3:5])
   V3  V4V5
1 ADaCGH_1.3-1.tar.gz 14-May-2007 12:04
2  AIS_1.0.tar.gz 31-Jul-2007 16:38
3 AMORE_0.2-10.tar.gz 11-Apr-2007 10:17
4   ARES_1.2-2.tar.gz 19-Mar-2007 20:53
5 AcceptanceSampling_0.1-1.tar.gz 07-Jul-2007 20:46
6   AdaptFit_0.2-1.tar.gz 04-Aug-2007 09:51

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 1:05 PM, Gabor Grothendieck wrote:
 On 8/24/07, Dirk Eddelbuettel [EMAIL PROTECTED] wrote:
 On Fri, Aug 24, 2007 at 10:57:46AM -0400, Duncan Murdoch wrote:
  On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
  On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
  On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
   Hi,
It is possible to use a shell command inside a R script?
I'm write a R script and I like to put somes shell commands inside to
  R.  Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
  The details and available functions depend on the platform, but you want
  to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in
  Windows; on Unix-alikes, you probably won't have the latter two.)
  Don't forget pipes. R's ability to consistently work on connections that
  may be local
  files, remotes files, program output, ... is a true treasure (and
  thanks and credits to, I believe, Brian Ripley to make it so).
  Eg you can do this   OD - read.table(pipe(links -dump
  http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, $4}'),
  header=FALSE, col.names=c(file, date))
  to get files and dates of files on CRAN.   As I recall, this also works on
  that other operating system, provided
  you do all the legwork of installing other tools, setting PATHs etc
  to provide what works out of the box on the supposedly unfriendlier OS.
 
  The pipe command you list doesn't work in Windows.  I'd guess this is
  because the pipe syntax | within the command is unsupported:  it tries to
  execute links, with the rest of the line passed as arguments.  But I
  haven't traced through to check on this.

 Hm, wishful thinking must have gotten the better of me then. Sorry for
 spreading misinformation about the capabilities of that other OS.
 
 This works for me on Windows:
 
 tab - read.table(pipe(lynx --nolist --dump 
 http://cran.r-project.org/src/contrib/ | findstr tar.gz), as.is = TRUE)

Which R version is that?  It doesn't work for me in Rgui, though it does 
  in Rterm, both R-devel versions.

Duncan Murdoch

 head(tab[3:5])
V3  V4V5
 1 ADaCGH_1.3-1.tar.gz 14-May-2007 12:04
 2  AIS_1.0.tar.gz 31-Jul-2007 16:38
 3 AMORE_0.2-10.tar.gz 11-Apr-2007 10:17
 4   ARES_1.2-2.tar.gz 19-Mar-2007 20:53
 5 AcceptanceSampling_0.1-1.tar.gz 07-Jul-2007 20:46
 6   AdaptFit_0.2-1.tar.gz 04-Aug-2007 09:51

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Duncan Murdoch
On 8/24/2007 11:14 AM, Dirk Eddelbuettel wrote:
 On Fri, Aug 24, 2007 at 10:57:46AM -0400, Duncan Murdoch wrote:
 On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
 On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
 On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
  Hi,
   It is possible to use a shell command inside a R script?
   I'm write a R script and I like to put somes shell commands inside to 
 R.  Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
 The details and available functions depend on the platform, but you want 
 to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in 
 Windows; on Unix-alikes, you probably won't have the latter two.)
 Don't forget pipes. R's ability to consistently work on connections that 
 may be local
 files, remotes files, program output, ... is a true treasure (and
 thanks and credits to, I believe, Brian Ripley to make it so).
 Eg you can do this   OD - read.table(pipe(links -dump 
 http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, $4}'), 
 header=FALSE, col.names=c(file, date))
 to get files and dates of files on CRAN.   As I recall, this also works on 
 that other operating system, provided
 you do all the legwork of installing other tools, setting PATHs etc
 to provide what works out of the box on the supposedly unfriendlier OS.

 The pipe command you list doesn't work in Windows.  I'd guess this is 
 because the pipe syntax | within the command is unsupported:  it tries to 
 execute links, with the rest of the line passed as arguments.  But I 
 haven't traced through to check on this.
 
 Hm, wishful thinking must have gotten the better of me then. Sorry for
 spreading misinformation about the capabilities of that other OS.

Actually, the OS is fine, it's R that's not.  I'll fix it for 2.6.0.

Duncan Murdoch

__
R-help@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.


Re: [R] It is possible to use a Shell command inside a R script?

2007-08-24 Thread Gabor Grothendieck
On 8/24/07, Duncan Murdoch [EMAIL PROTECTED] wrote:
 On 8/24/2007 1:05 PM, Gabor Grothendieck wrote:
  On 8/24/07, Dirk Eddelbuettel [EMAIL PROTECTED] wrote:
  On Fri, Aug 24, 2007 at 10:57:46AM -0400, Duncan Murdoch wrote:
   On 8/24/2007 10:33 AM, Dirk Eddelbuettel wrote:
   On Fri, Aug 24, 2007 at 08:32:00AM -0400, Duncan Murdoch wrote:
   On 8/24/2007 6:58 AM, Ronaldo Reis Junior wrote:
Hi,
 It is possible to use a shell command inside a R script?
 I'm write a R script and I like to put somes shell commands inside 
 to
   R.  Somethink like: convert fig01.png fig01.xpm or sed ..., etc.
   The details and available functions depend on the platform, but you 
   want
   to look at ?system, ?shell, and/or ?shell.exec.  (These all exist in
   Windows; on Unix-alikes, you probably won't have the latter two.)
   Don't forget pipes. R's ability to consistently work on connections that
   may be local
   files, remotes files, program output, ... is a true treasure (and
   thanks and credits to, I believe, Brian Ripley to make it so).
   Eg you can do this   OD - read.table(pipe(links -dump
   http://cran.r-project.org/src/contrib/ | awk '/tar.gz/ {print $3, 
   $4}'),
   header=FALSE, col.names=c(file, date))
   to get files and dates of files on CRAN.   As I recall, this also works 
   on
   that other operating system, provided
   you do all the legwork of installing other tools, setting PATHs etc
   to provide what works out of the box on the supposedly unfriendlier OS.
  
   The pipe command you list doesn't work in Windows.  I'd guess this is
   because the pipe syntax | within the command is unsupported:  it tries 
   to
   execute links, with the rest of the line passed as arguments.  But I
   haven't traced through to check on this.
 
  Hm, wishful thinking must have gotten the better of me then. Sorry for
  spreading misinformation about the capabilities of that other OS.
 
  This works for me on Windows:
 
  tab - read.table(pipe(lynx --nolist --dump 
  http://cran.r-project.org/src/contrib/ | findstr tar.gz), as.is = TRUE)

 Which R version is that?  It doesn't work for me in Rgui, though it does
  in Rterm, both R-devel versions.


I am using Rgui

 R.version.string
[1] R version 2.5.1 (2007-06-27)

on Windows XP.  lynx --version gives:

Lynx Version 2.8.5rel.1 (04 Feb 2004)
libwww-FM 2.14FM, SSL-MM 1.4.1, OpenSSL 0.9.7d-dev
Compiled by Borland C++ (Feb  5 2004 17:35:58).

Copyrights held by the University of Kansas, CERN, and other contributors.
Distributed under the GNU General Public License.
See http://lynx.isc.org/ and the online help for more information.

See http://www.moxienet.com/lynx/ for information about SSL for Lynx.
See http://www.openssl.org/ for information about OpenSSL.

__
R-help@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.