FAQ
<I was not sure if this should go to R-devel or R-help. If I e-mailed this
to the wrong place, please let me know.>

Hello dear R-devel members,

I came by an oddity, with regards to how character variables are being
transformed when they are in Hebrew, and when Sys.setlocale is changed.

Here is an example:


# first, let's set the locale to Hebrew
Sys.setlocale("LC_ALL", "Hebrew") # Setting locale
x <- "שלו�" # Now let's put "Peace" (in Hebrew) into variable x
x
#[1] "שלו�" # it is still correctly preserved

Sys.setlocale("LC_ALL", "English") # let's change the local
y <- "שלו�" # Now let's enter "peace" to variable y
x ; y # comparing variables x and y shows that x was changed while y wasn't

#[1] "ùìåí"
#[1] "שלו�"

# Do we want them to be different?

# Now If we run Sys.setlocale again, we won't see any change in y or x:
Sys.setlocale("LC_ALL", "English")
x ; y

#[1] "ùìåí"
#[1] "שלו�"


# while if we run it in Hebrew
Sys.setlocale("LC_ALL", "Hebrew")
x ; y # it will change x but not y
#[1] "שלו�"
#[1] "שלו�"

# and changing this back to English will only change x but not y
Sys.setlocale("LC_ALL", "English")
x ; y
#[1] "ùìåí"
#[1] "שלו�"


This leads me to two questions:
1) Is this a desired property of Sys.setlocale (or of the storage system of
the variables in R) ?
2) Is there a function that can change x to be like y?


Thanks,
Tal




----------------Contact
Details:-------------------------------------------------------
Contact me: tal.galili@gmail.com | 972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------

Search Discussions

  • Allan Engelhardt at Dec 15, 2010 at 8:35 am
    You are not saying which platform you are working on but my guess would
    be that the two locales have different character encodings. Try
    specifying the encoding explicitly in the format that is right for your
    platform; when I try to replicate your examples using

    Sys.setlocale("LC_ALL", "he_IL.utf8")
    Sys.setlocale("LC_ALL", "en_GB.utf8")

    (which is the correct syntax for my Fedora 14 Linux system) I do not see
    a problem, but changing the ".utf8" bit to something else for the second
    call exhibits similar behaviour to your example.

    Hope this helps a little.

    Allan.

    R version 2.13.0 Under development (unstable) (2010-12-14 r53851)
    Platform: x86_64-unknown-linux-gnu (64-bit)

    On 10/12/10 10:40, Tal Galili wrote:
    <I was not sure if this should go to R-devel or R-help. If I e-mailed this
    to the wrong place, please let me know.>

    Hello dear R-devel members,

    I came by an oddity, with regards to how character variables are being
    transformed when they are in Hebrew, and when Sys.setlocale is changed.

    Here is an example:


    # first, let's set the locale to Hebrew
    Sys.setlocale("LC_ALL", "Hebrew") # Setting locale
    x<- "שלו�" # Now let's put "Peace" (in Hebrew) into variable x
    x
    #[1] "שלו�" # it is still correctly preserved

    Sys.setlocale("LC_ALL", "English") # let's change the local
    y<- "שלו�" # Now let's enter "peace" to variable y
    x ; y # comparing variables x and y shows that x was changed while y wasn't

    #[1] "ùìåí"
    #[1] "שלו�"

    # Do we want them to be different?

    # Now If we run Sys.setlocale again, we won't see any change in y or x:
    Sys.setlocale("LC_ALL", "English")
    x ; y

    #[1] "ùìåí"
    #[1] "שלו�"


    # while if we run it in Hebrew
    Sys.setlocale("LC_ALL", "Hebrew")
    x ; y # it will change x but not y
    #[1] "שלו�"
    #[1] "שלו�"

    # and changing this back to English will only change x but not y
    Sys.setlocale("LC_ALL", "English")
    x ; y
    #[1] "ùìåí"
    #[1] "שלו�"


    This leads me to two questions:
    1) Is this a desired property of Sys.setlocale (or of the storage system of
    the variables in R) ?
    2) Is there a function that can change x to be like y?


    Thanks,
    Tal




    ----------------Contact
    Details:-------------------------------------------------------
    Contact me: tal.galili@gmail.com | 972-52-7275845
    Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
    www.r-statistics.com (English)
    ----------------------------------------------------------------------------------------------

    [[alternative HTML version deleted]]



    ______________________________________________
    r-devel@r-project.org mailing list
    https://stat.ethz.ch/mailman/listinfo/r-devel

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupr-devel @
categoriesr
postedDec 10, '10 at 10:40a
activeDec 15, '10 at 8:35a
posts2
users2
websiter-project.org
irc#r

2 users in discussion

Tal Galili: 1 post Allan Engelhardt: 1 post

People

Translate

site design / logo © 2022 Grokbase