[R] removing daylight savings in R

Rhiannon Marchant rhiannon.marchant at synergy.net.au
Wed Mar 11 02:33:35 CET 2009


   Hello,
   Thanks the Prof. Brian Ripley for his earlier response, however I still have
   a few issues with the times in R.
   I'd like to somehow set up R so it automatically has the timezone set to
   Western Australian standard time when I open up a workspace instead of
   Western Australian daylight savings time. Is this possible? I haven't had
   much luck in trying to find this.
   There are two main issues that I mentioned in my earlier email, in regards
   to the Oracle database I'm using the RODBC package to  extract the data into
   R. I've tried using the newer version of RODBC (1.2-4) and the older version
   (1.2-3) of this package and I still get the NA values for the 2am and 2:30am
   datetime values for the start of daylight savings.  However in R 2.6.2, I
   can use either version of RODBC without getting the error.
   The program is quite large, so I've just pickout the relevant bits of code
   needed to extract the data from Oracle
   >channel  <<-  odbcDriverConnect(paste("DSN=", dbdsn, ";UID=", dbuser,
   ";PWD=", dbpwd, sep=""), case="oracle")
   >total_cnsmptn_summary_vw<-sqlQuery(channel,             paste("select
   INTERVAL_START_DATETIME,   TOTAL_SMOOTHED_CNSMPTN_MWH+TOTAL_CHURN_MWH,
   NON_VEST_CNSMPTN_MWH+NON_VEST_CHURN_MWH,
   VEST_ISC_CNSMPTN_MWH+VEST_ISC_CHURN_MWH,
   TOTAL_SMOOTHED_CNSMPTN_MWH-NON_VEST_CNSMPTN_MWH-VEST_ISC_CNSMPTN_MWH+VEST_VC
   _CHURN_MWH from CONSUMPTION_SUMMARY where total_smoothed_cnsmptn_mwh > 0 and
   vest_isc_cnsmptn_mwh > 0 order by INTERVAL_START_DATETIME"))
   >names(total_cnsmptn_summary_vw)<-c('INTERVAL_START_DATETIME','TOTAL_SMOOTHE
   D_CNSMPTN_MWH','NON_VEST_CNSMPTN_MWH',
   'VEST_ISC_CNSMPTN_MWH','VEST_VC_CNSMPTN_MWH')
   >total_cnsmptn_summary_vw[67735:67745,]
                    INTERVAL_START_DATETIME    TOTAL_SMOOTHED_CNSMPTN_MWH
   NON_VEST_CNSMPTN_MWH VEST_ISC_CNSMPTN_MWH VEST_VC_CNSMPTN_MWH
   67735        2008-10-25  23:30:00                              535.437
   105.180               50.304             379.953
   67736        2008-10-26  00:00:00                              514.703
   104.700               50.376             359.627
   67737        2008-10-26  00:30:00                              499.146
   104.007               50.941             344.198
   67738        2008-10-26  01:00:00                              485.834
   102.486               50.479             332.869
   67739        2008-10-26  01:30:00                              474.799
   101.961               50.492             322.346
   67740                    <NA>                                       469.783
                102.070               50.755             316.958
   67741                      <NA>                                464.007
        100.814               50.816             312.377
   67742        2008-10-26  03:00:00                              463.224
   101.309               50.386             311.529
   67743        2008-10-26  03:30:00                              464.052
   102.049               50.207             311.796
   67744        2008-10-26  04:00:00                              469.753
   103.542               50.204             316.007
   67745        2008-10-26  04:30:00                              475.318
   105.407               49.670             320.241
   The second issue is the 2.8.1 version of R changing the times from a 2.6.2
   workspace - this probably relates to the display setting,  that  mentioned
   (I think if I can set this to always use Western Australian standard time
   the problem will be fixed, but I am unsure as how to do this)
   I create a datetime object in R 2.6.2 and then load that workspace into
   2.8.1 the time changes,
   In R 2.6.2 I've typed:
   >date1<-ISOdatetime(2008,1,1,8,00,00)
   >save.image("C:\\Data\\Profiles\\M063059\\Desktop\\test.RData")
   > date1
   [1] "2008-01-01 08:00:00 W. Australia Standard Time"
   and then in R 2.8.1 I've typed
   > load("C:\\Data\\Profiles\\M063059\\Desktop\\test.RData")
   > date1
   [1] "2008-01-01 09:00:00 WST"
   Kind Regards
   Rhiannon
   Rhiannon Marchant
   Forecasting Analyst
   Wholesale
   Synergy (ABN: 71 743 446 839), 228 Adelaide Tce, Perth, WA, 6000, Australia
   phone:   (08)   6212   1464   |   fax:   (08)   6212   1036  |  email:
   rhiannon.marchant at synergy.net.au
   business  enquiries:  131354 | identification no.: 300794  |  website:
   [1]synergy.net.au
   Please consider the environment before printing this email.

   Prof Brian Ripley <ripley at stats.ox.ac.uk>

   27/02/2009 03:42 PM

                                                                       To

   Rhiannon Marchant <rhiannon.marchant at synergy.net.au>

                                                                       cc

   r-help at r-project.org

                                                                  Subject

   Re: [R] removing daylight savings in R

   What do you mean by 'standard time'? If you mean UTC, set TZ=UTC.
   For anything else, see ?Sys.timezone (which explains the use of TZ).
   I am guessing that you are storing times in "POSIXct" objects (you do
   not say): they are in UTC.  Have you any evidence that 'datetimes are
   getting converted to daylight savings times'?  More likely they are
   getting *printed* in your local timezone, because that is the
   documented default behaviour.  But you can change it (see
   ?format.POSIXct).
   You are attributing self-will to R in 'an ORACLE database that R is
   importing data in from': it is merely following instructions.  We
   don't have those instructions and there is no sign of a package that
   could do this in your sessionInfo (R itself has no such facilities).
   If the Oracle database is not in your local timezone (which seems to
   be the case) you will need to tell the import facilty what time it is
   in.  If the (non-R) import facility does this right, the datetimes
   will be marked as being in UTC (or whatever), and most of the time
   printed as such (but I would always do so explicitly).
   The difference betwee 2.6.2 and later versions is that lots of bugs in
   the way Windows handles timezones were fixed, so it sounds as if you
   have been relying on a Windows bug.
   On Fri, 27 Feb 2009, Rhiannon Marchant wrote:
   >
   >   Hi all,
   >   I've been having some trouble with times in regards to daylight savings
   in R
   >   version 2.8.1.  I have an ORACLE database that R is importing data in
   from,
   >    for the 2am and 2:30am time intervals for the dates that daylight
   savings
   >   starts the times are getting read as NA values into R. I'm also finding
   that
   >   if  I  open a R workspace from version 6.2.2,the datetimes are getting
   >   converted to daylight savings times.  The times are a cruical part of my
   >   analysis and need to stay in standard time. I would like to be using a
   newer
   >   version of R than I am currently using (2.6.2) so that I can make use of
   the
   >   newer packages that are available, however with this problem of the time
   >   conversions I am unable to do this. Is anyone able to help with to set
   up
   >   R2.8.1 to use standard time instead of daylight savings times?
   [...]
   --
   Brian D. Ripley,                  ripley at stats.ox.ac.uk
   Professor of Applied Statistics,  [2]http://www.stats.ox.ac.uk/~ripley/
   University of Oxford,             Tel:  +44 1865 272861 (self)
   1 South Parks Road,                     +44 1865 272866 (PA)
   Oxford OX1 3TG, UK                Fax:  +44 1865 272595
   
   ========================================================================
   SYNERGY. ABN 71 743 446 839, Perth, Western Australia.
   Telephone: +61 8 6212 2222
   TO THE ADDRESSEE: Unencrypted E-mail is not secure and may not be authentic.
    We cannot guarantee the accuracy,
   reliability, completeness or confidentiality of this E-mail and any attachme
   nts ("E-Mail").
   The e-mail system used for this communication is based on Western Standard T
   ime.
   Please check all times carefully if they are important to the context of the
    communication.
   IF YOU ARE NOT THE INTENDED ADDRESSEE: This E-Mail is intended solely forthe
    intended addressee and may be subject
   to legal or other professional privilege, or may contain information that is
    confidential or exempt from
   disclosure by law. Copying or distributing this E-Mail or any information it
    may contain, by anyone other than the
   intended addressee, is prohibited. If you have received this E-Mail in error
    please notify us immediately by return
   e-mail or by telephone; and destroy this E-Mail and any electronic or hard c
   opies of it. Any claim to privilege or
   confidentiality is not waived or lost by reason of mistaken transmission of
   this E-Mail.
   VIRUSES: Although we scan all outgoing e-mail and attachments for viruses, w
   e cannot guarantee that viruses will not
   be transmitted with this E-mail. It is the recipient's responsibility to che
   ck this E-Mail for viruses.
   ========================================================================

References

   1. http://www.synergy.net.au/
   2. http://www.stats.ox.ac.uk/~ripley/



More information about the R-help mailing list