4

I can't figure out why the following line of R script works perfectly fine on Windows (7, 64bit with R 3.0.2 64bit) but not on Linux (3.12.1-1-ARCH GNU/Linux 64bit with R 3.0.2 64bit):

Windows:

>strptime("2013-05-08 10:27:50", format="%Y-%m-%d %H:%M:%S")
>[1] "2013-05-08 10:27:50"

Linux:

> strptime("2013-05-08 10:27:50", format="%Y-%m-%d %H:%M:%S")
>NA

There is some reference to "LC_TIME locale category" in the description of strptime but I really don't know if this is relevant to my problem.

Could somebody please explain, why the same line of code leads to different results and how I can make the Linux version of R behave the way of the Windows version?

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
  • 1
    Is the timezone the same on both machines? See `?Sys.timezone`. – Joshua Ulrich Nov 24 '13 at 14:27
  • 1
    Works for me on Linux - must be something to do with your particular Linux system's configuration. Try `export LC_ALL=C` in the shell before starting R. – zwol Nov 24 '13 at 14:40
  • No, it is not. Linux shows me "" and Windows "CET". Any idea how to change that? – Richard Kolodziej Nov 24 '13 at 14:42
  • For comparison you could try this in Python: `import datetime; datetime.datetime.strptime("2013-05-08 10:27:50", "%Y-%m-%d %H:%M:%S")` (it works for me on Mac OS). – John Zwinck Nov 24 '13 at 14:43
  • export LC_ALL=C doesn't change anything. I have the feeling, I have to somehow tell R, which timezone I'm at. – Richard Kolodziej Nov 24 '13 at 14:45
  • Thanks for the Python reference but this particular code line is from an R script I've written at work, where it works perfectly fine. Now I want it to work on my private Linux laptop. – Richard Kolodziej Nov 24 '13 at 14:47
  • Thanks to http://stackoverflow.com/a/6408072/3027391 I've changed the timezone of R to CET and Sys.timezone() now shows "CET" on Linux like on Windows. Still, the line of code does not work and shows NA. – Richard Kolodziej Nov 24 '13 at 15:04
  • ... Hmm, had I better posted this question to "CrossValidated"? It is rather a system problem and less a statistical problem. Guess I should have used the R mailing list. – Richard Kolodziej Nov 26 '13 at 07:01
  • Works fine on FreeBSD 10.0 and Windows... – crow16384 Sep 27 '14 at 14:28
  • Works on R-3.1.1, linux-3.11.0, with no timezone reported in R (`Sys.timezone() # NA`). Isn't CrossValidated more for pedagogical discussions? I'd think this is very much a StackOverflow (if an R problem) or SuperUser (if system based) issue. – r2evans Jan 03 '15 at 19:05
  • If you upgrade to the latest version, do you still have this problem? – Burhan Khalid Jan 15 '15 at 07:03
  • I've switched from Arch to Debian and it is working now with the default R installation (R 3.1.1 64bit)! – Richard Kolodziej Jan 16 '15 at 21:25

1 Answers1

0

It works in Arch Linux with 3.17.6-1-ARCH and R-3.1.2. My timezone is set as Asia/Kolkata but the output is slightly different, it shows the timezone as well.

strptime("2013-05-08 10:27:50", format="%Y-%m-%d %H:%M:%S") [1] "2013-05-08 10:27:50 IST".

j605
  • 26
  • 4