Stavros Macrakis wrote: > On Mon, Jun 1, 2009 at 11:33 AM, Wacek Kusnierczyk < > waclaw.marcin.kusnierc...@idi.ntnu.no> wrote: > > >> ... there is an ugly lack of consistency here:... >> >> > > I agree that it's inconsistent that > > 1:'2' --> 1:2 # this doesn't seem to be documented in ? seq > 1+ '2' --> error > 1+factor(2) --> NA (with a warning) > 1 : factor(4) --> 1 (uses as.numeric/unclass of factor) > > > >> ...i'd expect ...a successful computation (with a character -> numeric >> coercion of '2' to 2)... >> >> > > But I disagree that the best thing to do here is to have them all coerce to > numerics. In scripting languages like Perl which are constantly going back > and forth between internal and external representations, it makes some sense > to auto-convert numeric strings to numerics and vice versa, but I don't > think it makes sense in a statistical language. > > I would rather see them all give errors. >
i think either approach is correct in the scripting language r, provided the users do not have to navigate between exceptions and errors due to the inconsistent design. i agree that having 1:'2' result in an error might be better than what i suggested above. i said "i'd expect a successful computation" wrt. 1 * '2' not because i think it is the best r could do, but because r already messes with implicit coercions (as in 1:'2' and 1 + 0i, but not 1*'2' and sqrt(0i)), and it would be easier to learn if you could always expect a string to be (attempted to be) coerced to numeric in an arithmetic context. vQ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.