Sys.setlocale: request to set locale … cannot be honored

前端 未结 2 1979
抹茶落季
抹茶落季 2021-01-02 14:36

I\'m using strptime(...) in a function of my package. I need to parse a string using specific local settings and used Sys.setlocale as a workaround

相关标签:
2条回答
  • 2021-01-02 15:07

    I am quite sure that the "en_GB.UTF-8" locale is not installed on your college's computer. The easiest way could be to install it :) Well, this is not trivial with every OS.

    Other option could be to use a standard locale which can be found on every computer. As your added example shows no special format, you could try with setting LC_TIME to C, which works under Linux and Windows also. With that locale, your given example will work like a charm. See:

    > Sys.setlocale("LC_TIME", "C")
    > strptime("Mon, 14 Mar 2011 23:42:16 GMT", format = "%a, %d %b %Y %H:%M:%S", tz="GMT")
    [1] "2011-03-14 23:42:16 GMT"
    

    Or otherwise you should transform your data - e.g.: write a short function to substitute all week- and months' name to standard strings and restructure your imported strings to standard ones.

    0 讨论(0)
  • 2021-01-02 15:22

    I have tried your code on my Windows machine and get the same error. For reference, the results of Sys.getlocale("LC_TIME"):

    > Sys.getlocale("LC_TIME")
    [1] "English_United Kingdom.1252"
    

    I suspect this might be a fairly standard locale.

    But I also suspect that the better way of approaching this problem is to use some of the functions in package lubridate, which makes it easy to work with dates.

    You don't give enough details in your question what you are tring to do, but I am guessing that "sometext" is in a specific expected format, such as DMY or YMD. Lubridate provides functions to parse dates in any specified format, e.g. dmy(), ymd(), mdy() - you get the picture.

    If you provide more details about your real problem, we might be able to help more specifically.

    0 讨论(0)
提交回复
热议问题