From huber at ebi.ac.uk  Fri Jan 19 14:38:53 2007
From: huber at ebi.ac.uk (Wolfgang Huber)
Date: Fri, 19 Jan 2007 13:38:53 +0000
Subject: [Rd] combn implementation
In-Reply-To: <Pine.LNX.4.58.0701191413190.20958@ctt35.speech.kth.se>
References: <Pine.LNX.4.58.0701191413190.20958@ctt35.speech.kth.se>
Message-ID: <45B0C9ED.1080109@ebi.ac.uk>


Dear Giampiero,

> storage.mode(1)
[1] "double"
> storage.mode(1:1)
[1] "integer"

as.integer(1) would perhaps be the more pedagogical way to program this.

 Best wishes
 Wolfgang

------------------------------------------------------------------
Wolfgang Huber  EBI/EMBL  Cambridge UK  http://www.ebi.ac.uk/huber


> Hi,
> I was checking the source code to the function combn that "generates
> all combinations of the elements of 'x' taken 'm' at a time.",
> because I wished to modify it. I have a doubt about a statement.
> This is the main loop.
> 
>     ._1 <- 1:1
>     nmmp1 <- n - m + ._1
>     while (a[1] != nmmp1) {
>         if (e < n - h) {
>             h <- ._1
>             e <- a[m]
>             j <- ._1
>         }
>         else {
>             e <- a[m - h]
>             h <- h + ._1
>             j <- 1:h
>         }
>         a[m - h + j] <- e + j
>         r <- if (nofun)
>             x[a]
>         else FUN(x[a], ...)
>         if (simplify)
>             out[, i] <- r
>         else out[[i]] <- r
>         i <- i + 1
>     }
> 
> I wonder what is the meaning of the statement "._1 <- 1:1".
> First question: what is the difference with "._1 <- 1"?
> Second question (perhaps answerd by the answer to the first): why not
> using "1" directly? E.g.:
> [...]
> h <- 1
> e <- a[m]
> e <- 1
> [...]
> 
> Sorry if this is covered by the manuals, but it's not easy to search
> for the string "._1" with the usual search engines.
> Thank you!
> Giampiero



[Rd] combn implementation
Wolfgang Huber