Re: R-alpha: Recycling

Bill Venables (
Mon, 24 Feb 1997 19:40:51 +1030

Date: Mon, 24 Feb 1997 19:40:51 +1030
Message-Id: <>
From: Bill Venables <>
To: Jim Lindsey <>
Subject: Re: R-alpha: Recycling
In-Reply-To: <>

Jim Lindsey writes:
 > When I condemned recycling vectors, I did not mean to include
 > scalars as well.

S (and R) does not have a separate scalar type.

 > y <- x+1

 > should not create problems and should be allowed, as in GLIM.

 > y <- x+z
 > where x and z have different lengths, should be an error
 > instead of recycling the shorter one.  Jim

But this rule is exceptionally useful.  For example consider a
matrix product involving a diagonal matrix, say diag(d) %*% X.
You can either do it that way or simply by (d * X) using the
recycling rule.  If X is 10000 x 7, say, so d is a vector of
length 10000, which is quicker and uses less memory?

There may be a case for disallowing the recycling rule when the
longest length is not an exact multiple of all the shorter ones,
(and this is part of S version 4, in fact), but if you outlaw all
except "scalar" recycling you are really ditching a lot of power.

Bill Venables.
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: