From maechler at stat.math.ethz.ch  Mon Jul 31 15:38:42 2017
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon, 31 Jul 2017 15:38:42 +0200
Subject: [Rd] translateChar in NewName in bind.c
In-Reply-To: <712400930.2080961.1501426673388@mail.yahoo.com>
References: <712400930.2080961.1501426673388.ref@mail.yahoo.com>
 <712400930.2080961.1501426673388@mail.yahoo.com>
Message-ID: <22911.13026.582197.526670@stat.math.ethz.ch>

>>>>> Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org>
>>>>>     on Sun, 30 Jul 2017 14:57:53 +0000 writes:

    > R devel's bind.c has been ported to R patched. Is it OK while names of 'unlist' or 'c' result may be not strictly the same as in R 3.4.1 because of changed function 'NewName' in bind.c?

    > Using 'translateCharUTF8' instead of 'translateChar' is as it should be. It has an effect in non-UTF-8 locale for this example.

    > x <- list(1:2)
    > names(x) <- "\ue7"
    > res <- unlist(x)
    > charToRaw(names(res)[1])

    > Directly assigning 'tag' to 'ans' is more efficient, but
    > may be different from in R 3.4.1 that involves
    > 'translateCharUTF8', that is also correct. It has an
    > effect for this example. 

    > x <- 0
    > names(x) <- "\xe7"
    > Encoding(names(x)) <- "latin1"
    > res <- c(x)
    > Encoding(names(res))
    > charToRaw(names(res))

Yes, you are right, thank you:

That part of the changes in bind.c was *not* directly related to
the two R-bugs (PR#17284 & PR#17292)... and therefore, maybe I
should not have ported it to R-patched (= R 3.4.1 patched).

Your examples above are instructive..  notably the 2nd one seems
to demonstrate to me, that the change also *did* fix a bug:

   Encoding(names(res))

is "latin1" in R-devel  but interestingly is "UTF-8" in R 3.4.1,
indeed independently of the locale.

I would argue R-devel (and current R-patched) is more faithful
by keeping the Encoding "latin1" that was set for names(x) also
in the  names(c(x)) .

I could revert R-patched's  bind.c (so it only contains the two
official bug fixes PR#172(84|92)   but I wonder if it is
desirable in this case.

I'm glad for further reasoning.
Given current "knowledge"/"evidence",  I would not  revert
R-patched to R 3.4.1's behavior.

Martin

    > --------------------------------------------
    > On Tue, 13/6/17, Tomas Kalibera <tomas.kalibera at gmail.com> wrote:

    > Subject: Re: [Rd] translateChar in NewName in bind.c

    > @r-project.org
    > Date: Tuesday, 13 June, 2017, 2:35 PM

    > Thanks, fixed in R-devel.
    > Best
    > Tomas

    [.............]



[Rd] translateChar in NewName in bind.c
Martin Maechler