[R] Passing R connection as argument to a shell command on Windows

Mike Nielsen mr.blacksheep at gmail.com
Mon Sep 25 19:46:34 CEST 2006


No, the "cut" command won't understand that "z" is an R connection and
not a file in the current working directory: there is no overlap
between the R object name space and the Windows object name space.

Unfortunately, you may be forced to unzip to a temporary file, and
then read from that.

One thing that you might want to try, if you're using cygwin, is to
create a named pipe, and use "shell()" with wait=FALSE to unzip and
pipe into "cut" and then output to the named pipe.  Open an R
connection for reading from the named pipe.  This leaves open the
question of how to deal with failures, and whether you can invoke a
command pipeline from R under Windows...

I haven't tried this, so if you manage to make it work, it may be
something that's of interest to the list in general.

Regards,

Mike

On 9/25/06, Anupam Tyagi <AnupTyagi at yahoo.com> wrote:
> Hello, is there a way to pass a connection to a file in a zipped archive as
> argument (instead of a file name of unzipped file) to shell command "cut". In
> general, is it possible to pipe output of a R function to a shell command? How?
>
> I want to do something like:
>
> z = unz("zipArchive.zip", "fileASCII.ASC")
> # open connection
> open(z)
> # cut lines of the ASCII file in zipped archive at specific postions and send
> results to another file.
> shell("cut -c2-3,5-8 z > test2.dat")
>
> Anupam.
>
> ______________________________________________
> 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.
>


-- 
Regards,

Mike Nielsen



More information about the R-help mailing list