[R] documenting yoru progress
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Dec 3 03:01:38 CET 2007
Use format:
f <- function(x) {
format(match.call())
}
f(pi + 3)
On Dec 2, 2007 8:46 PM, tom sgouros <tomfool at as220.org> wrote:
>
> Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
>
> > Try this:
> >
> > > survey.write <- function(x) {
> > + print(match.call())
> > + x
> > + }
> > > out <- survey.write(pi+3)
> > survey.write(x = pi + 3)
>
> That's exactly what I need. Thank you.
>
> But now, another question. I can't seem to get the value returned by
> print() into a character variable. I tried examining the relevant print
> function, to see what it's printing, but there seems not to be a
> print.call(). This is not fatal, since I can use print(), but is there
> some obvious way to do this? as.character doesn't do it.
>
> More generally, is there a way to inspect an object of some class I
> don't know about to find its members and methods? I suspect that will
> save me some posts like this in the future.
>
> Thanks,
>
> -tom
>
>
>
>
> >
> >
> > On Dec 2, 2007 6:55 PM, tom sgouros <tomfool at as220.org> wrote:
> > >
> > >
> > > Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > >
> > > > If what you mean is that you have a file, test.R, of R commands
> > > > and you are using source("test.R") and you wish to discover the
> > > > name "test.R" without hard coding it in your file, then place this in
> > > > test.R:
> > > >
> > > > ofile <- parent.frame(2)$ofile
> > > >
> > > > and ofile will be set to "test.R". Note that the line shown should not
> > > > be within a function or other local environment within the file but
> > > > directly at top level.
> > >
> > > Thank you, that is an excellent hack, and I will use it carefully
> > > (though often), but it isn't quite what I had in mind.
> > >
> > > In my script called test.R, there is a function called "survey.write",
> > > which writes a report based on some survey results. It is called
> > > several times at the top level. I would like the report to say how
> > > "survey.write" was invoked, whether it was invoked as
> > > "survey.write(res.raw,res.q)" or "survey.write(bus.raw,bus.q)".
> > > Obviously I have access to the values of the arguments, but I want the
> > > names of those arguments, or a string containing it all.
> > >
> > > Thanks,
> > >
> > > -tom
> > >
> > >
> > > >
> > > > This is hack which may need to be modified if the internals of the
> > > > source command change.
> > > >
> > > > On Dec 2, 2007 6:24 PM, Tom Sgouros <tomfool at as220.org> wrote:
> > > > >
> > > > > Hello all:
> > > > >
> > > > > I have a function that writes a fairly elaborate report based on some
> > > > > survey data. For documentation and bookkeeping purposes, I'd like to
> > > > > write out in the report the function call that produced the report, or
> > > > > at least enough information to help me recreate the steps that led to
> > > > > that report. I've been generating all the reports with scripts, in
> > > > > order to be able to recreate the steps, but apart from the file name, I
> > > > > don't yet have a way to match the report to the script that created it.
> > > > >
> > > > > Can anyone suggest easy ways to do this? From within a function, is the
> > > > > function call text available somehow, or the names of the arguments used
> > > > > in the function invocation?
> > > > >
> > > > > Many thanks,
> > > > >
> > > > > -tom
> > > > >
> > > > >
> > > > > --
> > > > > ------------------------
> > > > > tomfool at as220 dot org
> > > > > http://sgouros.com
> > > > > http://whatcheer.net
> > > > >
> > > > > ______________________________________________
> > > > > R-help at r-project.org 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.
> > > > >
> > > >
> > >
> > >
> > > --
> > >
> > > ------------------------
> > > tomfool at as220 dot org
> > > http://sgouros.com
> > > http://whatcheer.net
> > >
> >
>
>
> --
>
> ------------------------
> tomfool at as220 dot org
> http://sgouros.com
> http://whatcheer.net
>
More information about the R-help
mailing list