From jmc at r-project.org  Thu Apr  1 21:05:59 2010
From: jmc at r-project.org (John Chambers)
Date: Thu, 01 Apr 2010 12:05:59 -0700
Subject: [Rd] as(1:4, "numeric") versus as.numeric(1:4, "numeric")
In-Reply-To: <4BB4CDBC.90208@userprimary.net>
References: <4BB3D21B.3030306@fhcrc.org> <4BB3E053.9020709@r-project.org>
	<4BB4CDBC.90208@userprimary.net>
Message-ID: <4BB4EE97.2090606@r-project.org>

On 4/1/10 9:45 AM, Seth Falcon wrote:
> So while I agree this could be considered obscure, this qualifies as a 
> bug in my book.  It seems desirable that selectMethod not change the 
> state of the system in a user-visible fashion.  And calling 
> selectMethod, or any other function, should not alter dispatch unless 
> documented to do so.
As I said in my reply to Herv?, if a change is proposed, I'd prefer it 
to be to disallow the selectMethod() call by not making coerce() a 
generic, or at least not one visible outside the namespace.

Your general stricture on selectMethod() sounds good, except that the 
function has the optional argument useInheritance=.  Then it will always 
be possible to have different side effects depending on how 
selectMethod() is called.  I would have no difficulty in principle with 
making the side-effects ONLY when it's called in the standard way, as 
happens implicitly from method dispatch.  To do that, however, requires 
making the change suggested in my previous paragraph, otherwise the user 
can  still frustrate the current implementation of as().
>
> I'm also suspicious of the behavior of the strict argument:
>
> > class(as(1:4, "numeric"))
> [1] "integer"
> > class(as(1:4, "numeric", strict = TRUE))
> [1] "integer"
> > class(as(1:4, "numeric", strict = FALSE))
> [1] "integer"
>
> Is that intended?
In the part of my mail you cut out, you'll see that this has to do with 
the semantics of
   class(from) <- "numeric"
I have no strong feelings on that, if someone wants to implement and 
defend a change.

John
>
> + seth
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] as(1:4, "numeric") versus as.numeric(1:4, "numeric")
John Chambers