From btyner at gmail.com  Tue Dec  8 00:37:08 2015
From: btyner at gmail.com (Benjamin Tyner)
Date: Mon, 7 Dec 2015 18:37:08 -0500
Subject: [Rd] For integer vectors, `as(x, "numeric")` has no effect.
In-Reply-To: <CAOwKfPTq9TZaV6j9KxbpFuDpZdyskDB9egL7B911QP3oaR6vOw@mail.gmail.com>
References: <CAOwKfPTq9TZaV6j9KxbpFuDpZdyskDB9egL7B911QP3oaR6vOw@mail.gmail.com>
Message-ID: <56661824.9020707@gmail.com>

Perhaps it is not that surprising, given that

     > mode(1L)
     [1] "numeric"

and

     > is.numeric(1L)
     [1] TRUE

On the other hand, this is curious, to say the least:

     > is.double(as(1L, "double"))
     [1] FALSE

> Here's the surprising behavior:
>
>     x <- 1L
>     xx <- as(x, "numeric")
>     class(xx)
>     ## [1] "integer"
>
> It occurs because the call to `as(x, "numeric")` dispatches the coerce
> S4 method for the signature `c("integer", "numeric")`, whose body is
> copied in below.
>
>      function (from, to = "numeric", strict = TRUE)
>      if (strict) {
>          class(from) <- "numeric"
>          from
>      } else from
>
> This in turn does nothing, even when strict=TRUE, because that
> assignment to class "numeric" has no effect:
>
>      x <- 10L
>      class(x) <- "numeric"
>      class(x)
>      [1] "integer"
>
> Is this the desired behavior for `as(x, "numeric")`?



[Rd] For integer vectors, `as(x, "numeric")` has no effect.
Benjamin Tyner