2

I try to convert the built-in time series sunspots data into an xts object and print it out with the following code:

sunspots.xts <- as.xts(sunspots)
sunspots.xts

The result looks like this

enter image description here

And here is my sessionInfo() output:

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese (Traditional)_Taiwan.950
[3] LC_MONETARY=Chinese (Traditional)_Taiwan.950 LC_NUMERIC=C
[5] LC_TIME=Chinese (Traditional)_Taiwan.950

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] xts_0.9-7 zoo_1.7-14 timeDate_3012.100

loaded via a namespace (and not attached):
[1] tools_3.3.2 grid_3.3.2 lattice_0.20-34 

The months are now written in traditional chinese but I want the output to remain in english. My R environment is completely in English. I guess somehow xts knows my operating system (win 8) to be working in traditional chinese and decides to change the expression of month into traditional chinese. There are similar discussions on the site and I have tried the following:

None of them works. I think it's because the question is somehow different. Your help would be greatly appreciated. Thank you.

Community
  • 1
  • 1
Todd Chou
  • 37
  • 5
  • What is the output of `sessionInfo()`? – Roland Mar 06 '17 at 13:23
  • Can you please edit a sample of the data into your question? Pictures of data are not particularly helpful. – Joshua Ulrich Mar 06 '17 at 13:47
  • @Roland: Thank you for the reply. The output of sessionInfo(): R version 3.3.2 (2016-10-31) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200) locale: [1] LC_COLLATE=Chinese (Traditional)_Taiwan.950 LC_CTYPE=Chinese (Traditional)_Taiwan.950 [3] LC_MONETARY=Chinese (Traditional)_Taiwan.950 LC_NUMERIC=C [5] LC_TIME=Chinese (Traditional)_Taiwan.950 – Todd Chou Mar 12 '17 at 12:26
  • attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] xts_0.9-7 zoo_1.7-14 timeDate_3012.100 loaded via a namespace (and not attached): [1] tools_3.3.2 grid_3.3.2 lattice_0.20-34 – Todd Chou Mar 12 '17 at 12:26
  • @Joshua: Thank you. I am not sure if I understand you correctly. It is the preloaded time series data set in R called sunspots. You could view it by writing sunspots(). – Todd Chou Mar 12 '17 at 12:34
  • You need to change your locale settings. See `help("Sys.setlocale")`. – Roland Mar 12 '17 at 12:42
  • Thank you very much. It works. – Todd Chou Mar 13 '17 at 13:52

1 Answers1

0

As Roland commented, you need to change your locale settings. If you change LC_TIME to "C" the times will print in English.

# Save current LC_TIME
def.locale <- Sys.getlocale("LC_TIME")

# Set LC_TIME=ja_JP.UTF-8
Sys.setlocale(category = "LC_TIME", locale = "ja_JP.UTF-8")
sunspots.xts <- as.xts(sunspots)
head(sunspots.xts)
#           [,1]
#  1月 1749 58.0
#  2月 1749 62.6
#  3月 1749 70.0
#  4月 1749 55.7
#  5月 1749 85.0
#  6月 1749 83.5

# Set LC_TIME=C
Sys.setlocale(category = "LC_TIME", locale = "C")
head(sunspots.xts)
#          [,1]
# Jan 1749 58.0
# Feb 1749 62.6
# Mar 1749 70.0
# Apr 1749 55.7
# May 1749 85.0
# Jun 1749 83.5

# Set locale back
Sys.setlocale(category = "LC_TIME", locale = def.locale)
Community
  • 1
  • 1
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418