From: Martin Maechler <maechler_at_stat.math.ethz.ch>

Date: Fri 19 Jan 2007 - 13:45:27 GMT

Giampiero> Giampiero

R-devel@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Jan 20 01:05:30 2007

Date: Fri 19 Jan 2007 - 13:45:27 GMT

Giampiero> Hi, Giampiero> I was checking the source code to the function combn that "generates Giampiero> all combinations of the elements of 'x' taken 'm' at a time.", Giampiero> because I wished to modify it. I have a doubt about a statement. Giampiero> 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> }

Not really!

You are not showing all the comments that go with it!
--> https://svn.R-project.org/R/trunk/src/library/utils/R/combn.R
is the current source file of the development version whereas

https://svn.r-project.org/R/tags/R-2-4-1/src/library/utils/R/combn.R is the R-2.4.1 version

Giampiero> I wonder what is the meaning of the statement "._1 <- 1:1".

The "real" source in 2.4.1 says

._1 <- 1:1 # to keep integer arithmetic ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So: It assigns "1:1" {the infamous short form for as.integer(1)}

to the variable '._1'

The variable name is a bit unusual and I had a little chuckle when I invented it to put there.

However with '1L' in R-devel, i.e. from R-2.5.0 on, code like the above will be definitely be simplified to use '1L' in such places, and then assigning it does not make sense anymore (of course it's questionable if it ever did make sense, but then, as I said, a had a chuckle and I think I found back then that it *did* increase speed slightly) ....

Giampiero> First question: what is the difference with "._1 <- 1"? explained in the comment

Giampiero> Second question (perhaps answerd by the answer to the first):

indeed it is.

Giampiero> why not using "1" directly? E.g.:

Giampiero> [...] Giampiero> h <- 1 Giampiero> e <- a[m] Giampiero> e <- 1 Giampiero> [...] Giampiero> Sorry if this is covered by the manuals, but it's not easy to search Giampiero> for the string "._1" with the usual search engines.Giampiero> Thank you!

Giampiero> Giampiero

You're welcome.

Martin Maechler, ETH Zurich

R-devel@r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Jan 20 01:05:30 2007

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Fri 19 Jan 2007 - 15:31:09 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel.
Please read the posting
guide before posting to the list.
*