Completion for custom "$" operator?

Vitalie S.

Completion for custom "$" operator?

Reply Threaded More More options
Print post
Permalink
Dear UseRs,

I declared a `$` method for a S4 class. Can I have ab automatic completion  
for this operator in R? Lists and environment objects provide this feature  
by default, but my object is an extension of "function" class which does  
not have subseting defined. How to be?

Thanks for any input.
Vitalie.

--

______________________________________________
[hidden email] 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.
Deepayan Sarkar

Re: Completion for custom "$" operator?

Reply Threaded More More options
Print post
Permalink
On Tue, Aug 4, 2009 at 11:37 AM, Vitalie S.<[hidden email]> wrote:
> Dear UseRs,
>
> I declared a `$` method for a S4 class. Can I have ab automatic completion
> for this operator in R? Lists and environment objects provide this feature
> by default, but my object is an extension of "function" class which does not
> have subseting defined. How to be?

Completion should be automatic if you define names() to return the valid names.

-Deepayan

______________________________________________
[hidden email] 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.
Vitalie S.

Re: Completion for custom "$" operator?

Reply Threaded More More options
Print post
Permalink

>
> Completion should be automatic if you define names() to return the valid  
> names.

Thank you Deepayan, that works beautifully. I wonder though; names  
function for environment objects always returns NULL, but completion still  
works. Looks tricky.

Vitalie.
--

______________________________________________
[hidden email] 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.
Deepayan Sarkar

Re: Completion for custom "$" operator?

Reply Threaded More More options
Print post
Permalink
On Thu, Aug 6, 2009 at 10:45 AM, Vitalie S.<[hidden email]> wrote:
>
>>
>> Completion should be automatic if you define names() to return the valid
>> names.
>
> Thank you Deepayan, that works beautifully. I wonder though; names function
> for environment objects always returns NULL, but completion still works.
> Looks tricky.

There's a special case coded-in for environments, where one needs to
use ls() [See utils:::specialCompletions].

-Deepayan

______________________________________________
[hidden email] 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.
Romain Francois

Re: Completion for custom "$" operator?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Deepayan Sarkar
On 08/04/2009 10:02 PM, Deepayan Sarkar wrote:

> On Tue, Aug 4, 2009 at 11:37 AM, Vitalie S.<[hidden email]>  wrote:
>> Dear UseRs,
>>
>> I declared a `$` method for a S4 class. Can I have ab automatic completion
>> for this operator in R? Lists and environment objects provide this feature
>> by default, but my object is an extension of "function" class which does not
>> have subseting defined. How to be?
>
> Completion should be automatic if you define names() to return the valid names.
>
> -Deepayan

Hi,

Shouldn't this be delegated to a custom method. ie :

complete <- function( x, ... ){
        UseMethod( "complete" )
}
complete.default <- function( x, ... ){
        names( x )
}

or maybe the equivalent S4 incantation.

This would separate the completion from the names, and therefore give
more flexibility to class writers.

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/vzip : Code Snippet : List of CRAN packages
|- http://tr.im/vsK1 : R parser package on CRAN
`- http://tr.im/vshK : Transfer files through Rserve

______________________________________________
[hidden email] 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.
Deepayan Sarkar

Re: Completion for custom "$" operator?

Reply Threaded More More options
Print post
Permalink
On 8/7/09, Romain Francois <[hidden email]> wrote:

> On 08/04/2009 10:02 PM, Deepayan Sarkar wrote:
>
> > On Tue, Aug 4, 2009 at 11:37 AM, Vitalie S.<[hidden email]>  wrote:
> >
> > > Dear UseRs,
> > >
> > > I declared a `$` method for a S4 class. Can I have ab automatic
> completion
> > > for this operator in R? Lists and environment objects provide this
> feature
> > > by default, but my object is an extension of "function" class which does
> not
> > > have subseting defined. How to be?
> > >
> >
> > Completion should be automatic if you define names() to return the valid
> names.
> >
> > -Deepayan
> >
>
>  Hi,
>
>  Shouldn't this be delegated to a custom method. ie :
>
>  complete <- function( x, ... ){
>         UseMethod( "complete" )
>  }
>  complete.default <- function( x, ... ){
>         names( x )
>  }
>
>  or maybe the equivalent S4 incantation.
>
>  This would separate the completion from the names, and therefore give more
> flexibility to class writers.

Ideally yes (although "complete" doesn't seem the best choice; this is
only for $ completion). It's an easy enough change, and I'll be happy
to make it if there's interest (and a use case where names() has good
reason to be different).

-Deepayan

______________________________________________
[hidden email] 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.
Romain Francois

Re: Completion for custom "$" operator?

Reply Threaded More More options
Print post
Permalink
On 08/07/2009 09:38 AM, Deepayan Sarkar wrote:

> On 8/7/09, Romain Francois<[hidden email]>  wrote:
>> On 08/04/2009 10:02 PM, Deepayan Sarkar wrote:
>>
>>> On Tue, Aug 4, 2009 at 11:37 AM, Vitalie S.<[hidden email]>   wrote:
>>>
>>>> Dear UseRs,
>>>>
>>>> I declared a `$` method for a S4 class. Can I have ab automatic
>> completion
>>>> for this operator in R? Lists and environment objects provide this
>> feature
>>>> by default, but my object is an extension of "function" class which does
>> not
>>>> have subseting defined. How to be?
>>>>
>>> Completion should be automatic if you define names() to return the valid
>> names.
>>> -Deepayan
>>>
>>   Hi,
>>
>>   Shouldn't this be delegated to a custom method. ie :
>>
>>   complete<- function( x, ... ){
>>          UseMethod( "complete" )
>>   }
>>   complete.default<- function( x, ... ){
>>          names( x )
>>   }
>>
>>   or maybe the equivalent S4 incantation.
>>
>>   This would separate the completion from the names, and therefore give more
>> flexibility to class writers.
>
> Ideally yes (although "complete" doesn't seem the best choice; this is
> only for $ completion). It's an easy enough change, and I'll be happy
> to make it if there's interest (and a use case where names() has good
> reason to be different).
>
> -Deepayan

The motivation for this was for java object references in rJava (jobjRef
class). See this: http://tr.im/vQkf

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/vzip : Code Snippet : List of CRAN packages
|- http://tr.im/vsK1 : R parser package on CRAN
`- http://tr.im/vshK : Transfer files through Rserve

______________________________________________
[hidden email] 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.