[R] pipe and binary i/o
Huntsinger, Reid
reid_huntsinger at merck.com
Mon Aug 5 21:35:56 CEST 2002
I often want to use "pipe" with "readBin" to read (binary) data from the
standard output of a Perl or C program. For that I need "pipe" to work with
the "open='rb'" option. It never worked for me, and after a look at the
connections.c file, I see that in "pipe_open" the mode gets passed directly
to "popen" (I'm using Linux on an Intel machine). Popen doesn't know "rb"
and fails. I modified the pipe function in connection.c to pass only the
first character of the mode. This seems to work (fingers crossed). Then I
noticed gzfile has the same problem, but bzfile doesn't, and uses the same
solution as I did for pipe. Can I assume that this is a correct fix? Or were
there reasons that pipe and gzfile wouldn't allow "rb"?
Thanks,
Reid Huntsinger
-----Original Message-----
From: Thomas Lumley [mailto:tlumley at u.washington.edu]
Sent: Monday, August 05, 2002 12:17 PM
To: Jim Lemon
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] filename of source file
On Mon, 5 Aug 2002, Jim Lemon wrote:
> David Richmond wrote:
> > Yes, source refers to the use of the source() function. Suppose I invoke
> > a file like so:
> >
> > source("/path/name/filename.r")
> >
> > I want to insert a command in filename.r like so:
> >
> > fullpath <- magic_command()
> >
> > such that fullpath is now "/path/name/filename.r"
> >
>
> How about
>
> source(fullpath<-"/path/name/filename.r") ?
>
That will work only when run at the top level.
If it isn't sufficient to know the directory
source("/path/name/filename.r",chdir=TRUE)
in which case magic.command() is getwd(), there isn't a nice way to do it.
Two not-so-nice ways
1) modify source() so it does something like
assign(".Last.source.file",file,envir=.GlobalEnv)
giving
magic.command<-function() get(".Last.source.file",envir=.GlobalEnv)
2) Get the file name from the environment inside source
magic.command<-function(){
n<-match("source",rev(as.character(sapply(sys.calls(),"[[",1))))
get("file", parent.frame(n-1)
}
The problem with the first is that it writes in the global workspace and
that it fails if a source()d file source()s another file before you use
magic.command().
The problem with the second is that it will break if the source() function
is
renamed or if the name of the variable "file" changes.
You also need to be aware that `file' need not be a filename. It could be
a URL [eg source("http://www.bioconductor.org/getBioC.R") ] or a
connection (either a file connection or some other sort).
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that may be confidential, proprietary copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by e-mail and then delete it.
==============================================================================
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list