[BioC] More environments facilities ?

Adrian Alexa adrian.alexa at gmail.com
Sat Oct 2 16:36:00 CEST 2004


On Fri, 1 Oct 2004 11:57:27 -0400, Robert Gentleman
<rgentlem at jimmy.harvard.edu> wrote:
> On Fri, Oct 01, 2004 at 04:58:40PM +0200, Adrian Alexa wrote:
> > Dear Bioconductor developers,
> >
> >
> > I'm using Bioconductor packages and I use more often environments. I
> > was happy to see that there are new functions in the Biobase package
> > that work with environments:   copyEnv, l2e, etc.
> 
>  And there are even more in R itself, things like $ and [[ work (but
>  NOT for numeric indices, only for character values and they do NOT do
>  partial matching). Also of note is as.list, which will coerce an
>  environment to a list. If you want something that let's you peak at
>  the values let me suggest DPExplorer.
> 
>  And also, please do note that eapply is a reasonable choice of apply
>  for environments.
> 
> 
> >
> > Unfortunately I didn't find a function that returns the 'lenght' (no.
> > of elements) of an environment. I know that I can do:
> >
> > > length(ls(env))
> 
>   why not length(env), which seems to both work and be faster...
> 
> 
> >
> > but I think this is slow and somehow redundant. Also I know that I can
> > write a simple C function, but I will like to have this facility into
> > R and not loading my function every time.
> >
> > I would like to know if such a function can (or will) be included into
> > a next version of biobase package.
> >
> >
> > Many thanks,
> >
> > Adrian
> >
> >




Thank you very much for your answer Robert. 


I know about the facilities that R offer for environments, but I was
saying that I found the new Biobase functions very useful . Probably I
wasn't to clear, so I will try to explain again what I wanted.


First, I'm using R 1.9.1 on a Debian Sarge machine and as far as I
observed eapply is not in this version (I sow is a R 2.0 feature,
which I think is great).


As for length(env) it does not work on this version. If this is a
facility of the new R 2.0 version that please excuse my impatience.
This is a small example of what I would expected:

> e <- new.env(hash = T, parent = NULL)
> assign('a', 1, e)
> assign('b', letters[1:5], e)
> length(e)
[1] 0
> length(ls(e))
[1] 2
> ls(e)
[1] "a" "b"



I'm working with GO and GOstats packages and I will like a function
that will do:


> envLen(GOTERM)
[1] 16843


Of course I can do

> length(ls(GOTERM))
[1] 16843


or


> length(as.list(GOTERM))
[1] 16843



but I think this is slow for big environments.


I sow, by looking at the envToList() C code that the length of the
environment can be easily obtain (using internal C function
length(env)), so I was taking about having a R version of this
function.


Thank you again for your answer, 

Adrian Alexa



More information about the Bioconductor mailing list