From ripley@stats.ox.ac.uk  Thu Jun 27 17:52:42 2002
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Thu, 27 Jun 2002 17:52:42 +0100 (BST)
Subject: data.frame does not recycle consistently (PR#1713)
In-Reply-To: <200206271613.SAA05140@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.31.0206271737430.23373-100000@gannet.stats>

On Thu, 27 Jun 2002 Kevin.Wright@pioneer.com wrote:

> Full_Name: Kevin Wright
> Version: 1.5.1
> OS: Windows 95
> Submission from: (NULL) (170.54.59.160)
>
>
>
> Note that the examples below do work in S (S-Plus 2000).
>
> It appears that data.frame does not recycle text strings.  Maybe has something
> to do with coercion to factors???

Yes, it is.  Not sure why that makes it inconsistent, though.
Vectors are recycled, other objects are not, and that is determined after
conversion to a column of a data frame.  We could fairly easily allow
factors and simple "AsIs" objects to be recycled.

BTW, S-PLUS 2000 is not S, and its data frame code is quite a lot
different from the original S code.  It also makes mistakes: compare

> data.frame(x=c("A","B"),y=I("C"))
> data.frame(x=c("A","B"),y=I(rep("C", 2)))


>
> > data.frame(x=1:2,y=1)
>   x y
> 1 1 1
> 2 2 1
>
> > data.frame(x=c("A","B"),y=T)
>   x    y
> 1 A TRUE
> 2 B TRUE
>
> > data.frame(x=c("A","B"),y="C")
> Error in data.frame(x = c("A", "B"), y = "C") :
>         arguments imply differing number of rows: 2, 1
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


data.frame does not recycle consistently (PR#1713)
ripley@stats.ox.ac.uk