I think you need to read ?setClass and ?setMethod. There is an example of 
defining a "[" method for a class that inherits from 'data.frame'. I suspect 
you need to capture the various possibilities for the arguments being present 
or missing.

-- 
David

Sent from my iPhone

On May 14, 2013, at 5:45 AM, Nhan Vu Lam Chi <nhani...@adatao.com> wrote:

> Dear David,
> 
> First, I would like to say thank you for your very soon reply. Second, I want 
> to clarify the question because it seems to not carrying exactly what I want 
> to ask. Let take an example on R data.frame:
> V1 <- 1
> df2 <- df[V1== 1,] # df is a data.frame, this command is correct, right?
> 
> The evaluation steps for the above command are:
> 1. R evaluate V1 > 1 to get TRUE
> 2. The command becomes df2 <- df[TRUE,] which copies all rows of df to df2
> 
> What I want is to capture the "V1 > 1" expression instead of letting R do the 
> evaluation in case of the custom [ function. Assume my class is mydf, the S4 
> function should be:
> setMethod("[", signature(x="mydf"), function(x,i,j,...,drop=TRUE) {
>                              e <- substitute(i)
>                              // do parsing and custom-evaluation tasks
> })
> 
> Currently, i is always a vector of type character, numeric or logic due to R 
> evaluation.
> 
> I am a newbie to R, so please tolerate my mistakes or misunderstanding. 
> Thanks!
> Nhan Vu
> 
> 
> 
> On Tue, May 14, 2013 at 12:14 PM, David Winsemius <dwinsem...@comcast.net> 
> wrote:
>> 
>> On May 13, 2013, at 6:38 PM, Nhan Vu Lam Chi wrote:
>> 
>> > Hi everyone,
>> > I currently work on a S4 class that has the [ function. I want to capture
>> > the unevaluated expression corresponding to the i param using substitute()
>> > function and do a non-standard evaluation. However R automatically
>> > evaluates the expression and give me its value.
>> > For example:
>> > Given mydf[mydf$V1 > 1,] with mydf is an object of my custom S4 dataframe
>> > class and V1 is one of its columns, I want to get the unevaluated
>> > expression mydf$V1 > 1.
>> >
>> > My questions are:
>> > 1. Is it possible to do that in R?
>> > 2. If yes, how to do?
>> 
>> Doesn't this cry out for the S4 class definition of "[" to be answerable?. 
>> Because "[" is generic, it could have almost any definition at the whim of 
>> the package author.
>> 
>> > My R version and OS info are:
>> > R version 2.15.3 (2013-03-01) -- "Security Blanket"
>> > Copyright (C) 2013 The R Foundation for Statistical Computing
>> > ISBN 3-900051-07-0
>> > Platform: x86_64-pc-linux-gnu (64-bit)
>> >
>> > This is the first time I post to the mailing list, so please forgive any
>> > mistakes and/or advise me if possible.
>> > Regards,
>> > Nhan Vu
>> >
>> >       [[alternative HTML version deleted]]
>> 
>> You are forgiven, but  this once, for posting in HTML.
>> 
>> --
>> David Winsemius
>> Alameda, CA, USA
> 

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to