[BioC] object programming problem

Sean Davis sdavis2 at mail.nih.gov
Tue Mar 1 14:45:30 CET 2005


On Mar 1, 2005, at 8:32 AM, Ian Jeffery wrote:

> Hi,
>
>     I have a programming problem that I have ran into once or twice 
> before
> Using the command ls returns the names of the files in the active R
> environment. I need to use the data contained in these files but ls() 
> only
> returns the names of the files. I'm wondering if there is a function 
> that
> can be used to access the data?
> An example of the problem is as follows.
>
>> ag<-1:10
>> bu<-c('h','e','l','p')
>> Ci<-ag
>> length(ag)
> [1] 10
>> length(ls()[1])
> [1] 1
>> ls()[1]
> [1] "ag"
>
> The length of ag is 10 but the length of its name is 1. How do I get 
> the
> length command to look at the data instead of the name?
>

sapply(ls(),function(x) {length(get(x))})

See ?get.

However, you may also want to consider using a list.  I think this is 
tangentially covered by an R-FAQ:

http://cran.r-project.org/doc/FAQ/R-FAQ.html

Look at 7.21.

Sean



More information about the Bioconductor mailing list