[R] own TAB expansion
Sebastian Gibb
lists at sebastiangibb.de
Sat Oct 9 20:13:11 CEST 2010
Am Samstag, 9. Oktober 2010, 08:39:36 schrieb Deepayan Sarkar:
> On Fri, Oct 8, 2010 at 6:19 AM, Sebastian Gibb <lists at sebastiangibb.de>
wrote:
> > Hello Duncan,
> >
> > thank for your advice, but it doesn't work like expected:
> >
> > setClass(Class="A", representation=representation(slotA="numeric",
> > slotB="numeric"));
> > setMethod("$", "A", function(x, name) {return(slot(x, name));})
> > setGeneric(".DollarNames")
> > setMethod(".DollarNames", signature(x="A"), function(x,
> > pattern)grep(pattern=pattern, x=c("slotA", "slotB"), value=T))
> >
> > a <- new("A", slotA=1, slotB=2)
> > a$sl <TAB>
> > # doesn't print slotA/slotB
> >
> >> a$
> >
> > What I'm doing wrong?
>
> There is a namespace issue with making .DollarNames() generic;
> basically, the completion code in the utils namespace never sees the
> new S4 generic. See a previous discussion at
>
> http://www.mail-archive.com/r-devel@r-project.org/msg20553.html
>
> Defining a S3 method should work (without the need for a dummy S3
> class even with inheritance if you are working with R 2.12):
>
> .DollarNames.A <-
> function(x, pattern) {
> grep(pattern=pattern, x=c("slotA", "slotB"), value=T)
> }
>
> -Deepayan
Hello Deepayan,
thanks for the link. This solution works for R 2.12.
Bye
Sebastian
More information about the R-help
mailing list