Perhaps,

object <- sapply(ls(),
                 function(x)class(eval(parse(text=x))))

object[grep("character", object)]



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

On 23/09/2007, Zhang Honglian <[EMAIL PROTECTED]> wrote:
>
>
>    Hello,
>
>    I would like to find all objects of a particular class. Is that
> possible to
>    do so in R? I knew that in SPLUS, the function
> objects(class="classname")
>    can do this. But in R, I cannot find the similar function to do so. Is
> there
>    any way that I can distinguish where an object comes from? E.g. I
> defined a
>    class "person". Then I generated three objects from it (e.g, Joe, Lee,
> Dan).
>    I also have some other objects in the workspace (not from class
> "person").
>    How do I suppose to know in the current workspace I have exactly three
>    objects  (Joe,  Lee, Dan) from the class "person"? For example, in the
>    following program, at the final step when I run objects(), it will give
> me
>    not only "Joe" ""Lee" and "Dan", but also "x". If I run some other
> programs
>    before this, I might have other objects too. How can I let R only give
> me
>    "Joe" ""Lee" and "Dan"?
>
>    Any help will be highly appreciated,
>
>    Honglian
>
>    setClass("person",
>
>    representation(Name="character",
>
>    PhoneNo="character", Address="character"))
>
>    setMethod("show", "person",
>
>    function(object)
>
>    {
>
>    x<- data.frame ([EMAIL PROTECTED], [EMAIL PROTECTED],
>
>    [EMAIL PROTECTED])
>
>    print(x)
>
>    }
>
>    )
>
>    Joe =  new("person", Name='Joe', PhoneNo='(210)481-5720', Address='San
>    Antonio')
>
>    Dan = new("person", Name='Dan', PhoneNo='(413)583-5202',
> Address='Boston')
>
>    Lee = new("person", Name='Lee', PhoneNo='(519)837-1291',
> Address='Toronto')
>
>    x <- objects()
>
>    objects()
>      _________________________________________________________________
>
>    Express yourself instantly with MSN Messenger! [1]MSN Messenger
> Download
>    today it's FREE!
>
> References
>
>    1. http://g.msn.com/8HMAEN/2737??PS=47575
> ______________________________________________
> 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.
>

        [[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