Re: [R] srt --- slope text with function?

From: ivo welch <ivowel_at_gmail.com>
Date: Tue 07 Feb 2006 - 06:48:14 EST

Thank you, as always.

May I disagree with you and offer a suggestion?

In the best of worlds, a function should have multiple attributes. In addition to the function name and its argument list, two mandatory attributes should be a filename and lineno. If the function is interactively created, perhaps we can call the filename "-" and the lineno a count that could come from the history(). Yes, it will *NOT* be perfect, but it would be a big improvement.

If functions can have attributes, in addition to keeping the filename and lineno, it would be great if it could have an immediate association with a short documentation message? This could be a neat documentation crutch, useful, e.g., in ls.str() or a describe(). the best syntax that I can think of just stinks, but maybe a standard argument does the job and should be encouraged.   xyz <- function(args, doc="xyz returns 0") { return(0); } I do not think the following syntax would work stylewise:   xyz <- function "xyz returns 0" (args) { return(0); } but it would be nicer in noting the difference between a normal argument and a short function descriptor.

regards,

/iaw

by traceback(), do you mean the gdb() like traceback of the R internals? This would not be too helpful to most users. I would be more interested in my R call stack, not my underlying C call stack.

[and thanks again for all the other info].

regards,

/iaw

On 2/6/06, Prof Brian Ripley <ripley@stats.ox.ac.uk> wrote:

> 'Actually', R does what you ask it to: see options(error). But before the
> program stops, there is no error to report. In interactive use I see no
> problem in typing traceback() or using recover() (see below), but for
> batch use we are looking at alternatives. For example, in R 2.3.0
> (modern) Unix users will get a traceback after a segfault.
>
> > There's going to be a new section on debugging in the R 2.3.0 "Writing R
> > Extensions" manual (written by Brian Ripley). You can see it now if you
> > build R-devel (or download a binary build from CRAN; I put Windows
> > builds there approximately daily). I also put together a
> > Windows-oriented debugging page at
> > http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/.
>
> filename+lineno makes no sense: R functions are not (in the main) from
> files. They can be autogenerated (and often are). And I can 'fix' them.
>
> As for the call stack, try options(error=recover) and 'where': see the
> chapter Duncan pointed you to.
>
> >> * is there a way to print all my user defined functions? I have an
> >> init file, in which I am defining all sorts of useful utility
> >> functions, and I would like to print what I have defined (for memory)
> >> upon a read of this init file? that is, something that has
> >> functionality like
> >> note.all.local.definitions.now.in.vector( all.local.functions )
> >> a <- function() { }
> >> b <- function() { }
> >> cat( all.local.functions ); # should print 'a' and 'b'.
> >
> > ls.str() includes an option to select only functions. You could also
> > write your own filter for ls() output.
> >>
> >> * is there a string variable that gives me the name of the current
> >> function I am in?
> >
> > I don't think so, but sys.call() gets close. Watch out though: the
> > name you see will be the name used by the caller, which may not be the
> > name used when the function was written. For example, in a function
> > called from apply(), you'll see FUN, not the original name. Objects
> > don't know their own names in general, because they keep getting passed
> > around.
>
> In the debugging context the command 'where' tells you the sequence of
> calls (which can be more helpful).
>
> More generally, functions need not even have names (Bill Venables calls
> them 'anonymous functions'), as in
>
> r <- sapply(nms,
> function(n) if (exists(n, envir = envir, mode = mode))n
> else as.character(NA))
>
> from ls.str.
>
>
> --
> Brian D. Ripley, ripley@stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
>



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 Received on Tue Feb 07 06:56:55 2006

This archive was generated by hypermail 2.1.8 : Tue 07 Feb 2006 - 08:37:17 EST