R does not show special characters coming from json source












2















a little bit about the background.
I pull data from an API that supplies public transportation data. It returns the result in json format, which I process with the library 'jsonlite'.



 resp <- GET(url = url)


resp_char <- rawToChar(resp$content)
parsed <- fromJSON(resp_char, flatten = T)

parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))


The problem is, in the result there are no special characters.



I am working on a Windows Server 2012 machine and my language settings in R look like this:



    > Sys.getlocale()
[1] "LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252"


Example:



    > df$direction
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"Märkisches Viertel, Wilhelmsruher Damm"


The expected result for the fifth result is "Märkisches Viertel, Wilhelmsruher Damm"



After that I looked in the actual encoding.



> Encoding(df$direction)
[1] "unknown" "unknown" "unknown" "unknown" "UTF-8"


In my opinion this looks good so far, but nevertheless I cannot see special characters.



I appreciate any suggestions and ideas on the subject.



Regards










share|improve this question























  • have you tried this function iconv?

    – amrrs
    Sep 8 '17 at 10:33











  • Yes I tried. That is the result > iconv(tmpStore2$direction,to ="UTF8") [1] "U Alt-Mariendorf (Berlin)" "U Alt-Tegel (Berlin)" "U Alt-Mariendorf (Berlin)" [4] "U Alt-Tegel (Berlin)" "Märkisches Viertel, Wilhelmsruher Damm"

    – ahLoco
    Sep 8 '17 at 10:52


















2















a little bit about the background.
I pull data from an API that supplies public transportation data. It returns the result in json format, which I process with the library 'jsonlite'.



 resp <- GET(url = url)


resp_char <- rawToChar(resp$content)
parsed <- fromJSON(resp_char, flatten = T)

parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))


The problem is, in the result there are no special characters.



I am working on a Windows Server 2012 machine and my language settings in R look like this:



    > Sys.getlocale()
[1] "LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252"


Example:



    > df$direction
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"Märkisches Viertel, Wilhelmsruher Damm"


The expected result for the fifth result is "Märkisches Viertel, Wilhelmsruher Damm"



After that I looked in the actual encoding.



> Encoding(df$direction)
[1] "unknown" "unknown" "unknown" "unknown" "UTF-8"


In my opinion this looks good so far, but nevertheless I cannot see special characters.



I appreciate any suggestions and ideas on the subject.



Regards










share|improve this question























  • have you tried this function iconv?

    – amrrs
    Sep 8 '17 at 10:33











  • Yes I tried. That is the result > iconv(tmpStore2$direction,to ="UTF8") [1] "U Alt-Mariendorf (Berlin)" "U Alt-Tegel (Berlin)" "U Alt-Mariendorf (Berlin)" [4] "U Alt-Tegel (Berlin)" "Märkisches Viertel, Wilhelmsruher Damm"

    – ahLoco
    Sep 8 '17 at 10:52
















2












2








2








a little bit about the background.
I pull data from an API that supplies public transportation data. It returns the result in json format, which I process with the library 'jsonlite'.



 resp <- GET(url = url)


resp_char <- rawToChar(resp$content)
parsed <- fromJSON(resp_char, flatten = T)

parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))


The problem is, in the result there are no special characters.



I am working on a Windows Server 2012 machine and my language settings in R look like this:



    > Sys.getlocale()
[1] "LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252"


Example:



    > df$direction
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"Märkisches Viertel, Wilhelmsruher Damm"


The expected result for the fifth result is "Märkisches Viertel, Wilhelmsruher Damm"



After that I looked in the actual encoding.



> Encoding(df$direction)
[1] "unknown" "unknown" "unknown" "unknown" "UTF-8"


In my opinion this looks good so far, but nevertheless I cannot see special characters.



I appreciate any suggestions and ideas on the subject.



Regards










share|improve this question














a little bit about the background.
I pull data from an API that supplies public transportation data. It returns the result in json format, which I process with the library 'jsonlite'.



 resp <- GET(url = url)


resp_char <- rawToChar(resp$content)
parsed <- fromJSON(resp_char, flatten = T)

parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))


The problem is, in the result there are no special characters.



I am working on a Windows Server 2012 machine and my language settings in R look like this:



    > Sys.getlocale()
[1] "LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252"


Example:



    > df$direction
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"U Alt-Mariendorf (Berlin)"
"U Alt-Tegel (Berlin)"
"Märkisches Viertel, Wilhelmsruher Damm"


The expected result for the fifth result is "Märkisches Viertel, Wilhelmsruher Damm"



After that I looked in the actual encoding.



> Encoding(df$direction)
[1] "unknown" "unknown" "unknown" "unknown" "UTF-8"


In my opinion this looks good so far, but nevertheless I cannot see special characters.



I appreciate any suggestions and ideas on the subject.



Regards







json r windows utf-8 jsonlite






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 8 '17 at 10:31









ahLocoahLoco

314




314













  • have you tried this function iconv?

    – amrrs
    Sep 8 '17 at 10:33











  • Yes I tried. That is the result > iconv(tmpStore2$direction,to ="UTF8") [1] "U Alt-Mariendorf (Berlin)" "U Alt-Tegel (Berlin)" "U Alt-Mariendorf (Berlin)" [4] "U Alt-Tegel (Berlin)" "Märkisches Viertel, Wilhelmsruher Damm"

    – ahLoco
    Sep 8 '17 at 10:52





















  • have you tried this function iconv?

    – amrrs
    Sep 8 '17 at 10:33











  • Yes I tried. That is the result > iconv(tmpStore2$direction,to ="UTF8") [1] "U Alt-Mariendorf (Berlin)" "U Alt-Tegel (Berlin)" "U Alt-Mariendorf (Berlin)" [4] "U Alt-Tegel (Berlin)" "Märkisches Viertel, Wilhelmsruher Damm"

    – ahLoco
    Sep 8 '17 at 10:52



















have you tried this function iconv?

– amrrs
Sep 8 '17 at 10:33





have you tried this function iconv?

– amrrs
Sep 8 '17 at 10:33













Yes I tried. That is the result > iconv(tmpStore2$direction,to ="UTF8") [1] "U Alt-Mariendorf (Berlin)" "U Alt-Tegel (Berlin)" "U Alt-Mariendorf (Berlin)" [4] "U Alt-Tegel (Berlin)" "Märkisches Viertel, Wilhelmsruher Damm"

– ahLoco
Sep 8 '17 at 10:52







Yes I tried. That is the result > iconv(tmpStore2$direction,to ="UTF8") [1] "U Alt-Mariendorf (Berlin)" "U Alt-Tegel (Berlin)" "U Alt-Mariendorf (Berlin)" [4] "U Alt-Tegel (Berlin)" "Märkisches Viertel, Wilhelmsruher Damm"

– ahLoco
Sep 8 '17 at 10:52














2 Answers
2






active

oldest

votes


















2














So finally I got it.
Thanks to @parth, it has led me to the right answer.
I used Encoding before my fromJSON statement and that worked for me.



  resp <- GET(url = url)

resp_char <- rawToChar(resp$content)
Encoding(resp_char) <- "UTF-8"
parsed <- fromJSON(resp_char, flatten = T)

parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))





share|improve this answer































    0














    Using the dataframe



    df<-data.frame(direction=c("U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","Märkisches Viertel, Wilhelmsruher Damm"), stringsAsFactors = FALSE)



    > df
    direction
    1 U Alt-Mariendorf (Berlin)
    2 U Alt-Tegel (Berlin)
    3 U Alt-Mariendorf (Berlin)
    4 U Alt-Tegel (Berlin)
    5 Märkisches Viertel, Wilhelmsruher Damm


    Now, just change the encoding of entire df$direction column as



    Encoding(df$direction) <- "UTF-8"


    which fixes the issue



    > df
    direction
    1 U Alt-Mariendorf (Berlin)
    2 U Alt-Tegel (Berlin)
    3 U Alt-Mariendorf (Berlin)
    4 U Alt-Tegel (Berlin)
    5 Märkisches Viertel, Wilhelmsruher Damm





    share|improve this answer
























    • Unfortunately it is just working in your example. The difference ist, that my Dataframe already is UTF-8 encoded (see above). Your code is in Latin1 and then it works.. (converting my dataframe in latin1 and back to utf-8 does not work)

      – ahLoco
      Sep 8 '17 at 11:03











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46114449%2fr-does-not-show-special-characters-coming-from-json-source%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    So finally I got it.
    Thanks to @parth, it has led me to the right answer.
    I used Encoding before my fromJSON statement and that worked for me.



      resp <- GET(url = url)

    resp_char <- rawToChar(resp$content)
    Encoding(resp_char) <- "UTF-8"
    parsed <- fromJSON(resp_char, flatten = T)

    parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))





    share|improve this answer




























      2














      So finally I got it.
      Thanks to @parth, it has led me to the right answer.
      I used Encoding before my fromJSON statement and that worked for me.



        resp <- GET(url = url)

      resp_char <- rawToChar(resp$content)
      Encoding(resp_char) <- "UTF-8"
      parsed <- fromJSON(resp_char, flatten = T)

      parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))





      share|improve this answer


























        2












        2








        2







        So finally I got it.
        Thanks to @parth, it has led me to the right answer.
        I used Encoding before my fromJSON statement and that worked for me.



          resp <- GET(url = url)

        resp_char <- rawToChar(resp$content)
        Encoding(resp_char) <- "UTF-8"
        parsed <- fromJSON(resp_char, flatten = T)

        parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))





        share|improve this answer













        So finally I got it.
        Thanks to @parth, it has led me to the right answer.
        I used Encoding before my fromJSON statement and that worked for me.



          resp <- GET(url = url)

        resp_char <- rawToChar(resp$content)
        Encoding(resp_char) <- "UTF-8"
        parsed <- fromJSON(resp_char, flatten = T)

        parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame))






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 8 '17 at 14:48









        ahLocoahLoco

        314




        314

























            0














            Using the dataframe



            df<-data.frame(direction=c("U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","Märkisches Viertel, Wilhelmsruher Damm"), stringsAsFactors = FALSE)



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm


            Now, just change the encoding of entire df$direction column as



            Encoding(df$direction) <- "UTF-8"


            which fixes the issue



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm





            share|improve this answer
























            • Unfortunately it is just working in your example. The difference ist, that my Dataframe already is UTF-8 encoded (see above). Your code is in Latin1 and then it works.. (converting my dataframe in latin1 and back to utf-8 does not work)

              – ahLoco
              Sep 8 '17 at 11:03
















            0














            Using the dataframe



            df<-data.frame(direction=c("U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","Märkisches Viertel, Wilhelmsruher Damm"), stringsAsFactors = FALSE)



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm


            Now, just change the encoding of entire df$direction column as



            Encoding(df$direction) <- "UTF-8"


            which fixes the issue



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm





            share|improve this answer
























            • Unfortunately it is just working in your example. The difference ist, that my Dataframe already is UTF-8 encoded (see above). Your code is in Latin1 and then it works.. (converting my dataframe in latin1 and back to utf-8 does not work)

              – ahLoco
              Sep 8 '17 at 11:03














            0












            0








            0







            Using the dataframe



            df<-data.frame(direction=c("U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","Märkisches Viertel, Wilhelmsruher Damm"), stringsAsFactors = FALSE)



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm


            Now, just change the encoding of entire df$direction column as



            Encoding(df$direction) <- "UTF-8"


            which fixes the issue



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm





            share|improve this answer













            Using the dataframe



            df<-data.frame(direction=c("U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","U Alt-Mariendorf (Berlin)","U Alt-Tegel (Berlin)","Märkisches Viertel, Wilhelmsruher Damm"), stringsAsFactors = FALSE)



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm


            Now, just change the encoding of entire df$direction column as



            Encoding(df$direction) <- "UTF-8"


            which fixes the issue



            > df
            direction
            1 U Alt-Mariendorf (Berlin)
            2 U Alt-Tegel (Berlin)
            3 U Alt-Mariendorf (Berlin)
            4 U Alt-Tegel (Berlin)
            5 Märkisches Viertel, Wilhelmsruher Damm






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 8 '17 at 10:53









            parthparth

            908518




            908518













            • Unfortunately it is just working in your example. The difference ist, that my Dataframe already is UTF-8 encoded (see above). Your code is in Latin1 and then it works.. (converting my dataframe in latin1 and back to utf-8 does not work)

              – ahLoco
              Sep 8 '17 at 11:03



















            • Unfortunately it is just working in your example. The difference ist, that my Dataframe already is UTF-8 encoded (see above). Your code is in Latin1 and then it works.. (converting my dataframe in latin1 and back to utf-8 does not work)

              – ahLoco
              Sep 8 '17 at 11:03

















            Unfortunately it is just working in your example. The difference ist, that my Dataframe already is UTF-8 encoded (see above). Your code is in Latin1 and then it works.. (converting my dataframe in latin1 and back to utf-8 does not work)

            – ahLoco
            Sep 8 '17 at 11:03





            Unfortunately it is just working in your example. The difference ist, that my Dataframe already is UTF-8 encoded (see above). Your code is in Latin1 and then it works.. (converting my dataframe in latin1 and back to utf-8 does not work)

            – ahLoco
            Sep 8 '17 at 11:03


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46114449%2fr-does-not-show-special-characters-coming-from-json-source%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin