Last data update: 2014.03.03

R: Date time handling for the GENEAread package.
GRtimeR Documentation

Date time handling for the GENEAread package.

Description

Stores date time data as a numeric, with facility for pretty printing and axis commands.

Usage

convert.time(x, format = NULL)
as.GRtime(x, format = NULL, ...)
## S3 method for class 'GRtime'
format(x, format = NULL, ...)
## S3 method for class 'GRtime'
axis(side, x=NULL, at=NULL, format = NULL,labels  = TRUE, add = TRUE,  ...)
## S3 method for class 'GRtime'
pretty(x, n = 5, ...)

Arguments

x

Object to process. For convert.time, must be numeric. For as.GRtime may be numeric or character. For format.GRtime, a GRtime object, or a numeric.

format

A character string indicating the form of output. See strptime for details. If NULL, will be automatically chosen.

add

logical. If TRUE, actually plot the axis.

at, side, labels

Additional arguments as in axis.

n

Approximate number of breakpoints.

...

Additional arguments to be passed to parse.time, as.numeric, format.POSIXct, axis, pretty.POSIXt.

Details

The GRtime class handles dates and times for the GENEAread class. The class treats dates as numerics denoting seconds since the UNIX epoch, with potentially a string attached specifying the format to print in. Unlike POSIXct, we avoid some of the processing, especially with respect to time zones, and allow some more flexibility in time computation and display. A range of operators are defined.

convert.time converts numerics to GRtime objects. The format argument allows a format string to be attached specifying the default format to display in. as.GRtime is a wrapper to convert.time, that when supplied with character input, coerces the value first to numeric using parse.time.

format.GRtime formats GRtime objects for pretty printing. If format is provided as argument, that is used. Else, if the format attribute is set on x, that is used. Finally, if formats are not provided, and x is of length greater than one, the range of values of x is used to decide the units displayed. Numerics are also accepted - they are coerced to GRtime.

axis.GRtime is used to plot GRtime axis, choosing, by default, breakpoints that give 'pretty' sub intervals. Note that plot.default uses axis.GRtime by default if supplied with a GRtime object in one of the directions. However, image.default based functions do not use the class axis functions, so axes must be plotted manually.

pretty.GRtime computes 'pretty' breakpoints, using the algorithm of pretty.POSIXt. Attributes are preserved.

Value

For convert.time, as.GRtime and pretty.GRtime, a GRtime object.

For format.GRtime a character string representation.

For axis.GRtime a list containing positions and labels for axis markers.

See Also

parse.time, get.intervals, print.AccData

Examples

as.GRtime("00:01")
#format is automatically set
convert.time(1:10)
convert.time(1:10*1000)
#we add a different default format
convert.time(1:10*1000, "%H:%M:%OS3") -> t
t
str(t)
#we override format with our own
format(t, format = "%a %d/%m/%y %H:%M:%OS3")

#plot calls axis.GRtime automatically. Notice
#that the format attribute is used.
plot(t, 1:10)
#strip out the default format
t2 = convert.time(t, format = NULL)
plot(t2, 1:10)

#image plots are a bit more complex

Z = matrix(rnorm(100), 10)
image(x = t, y = t2, z = Z, axes = FALSE)
axis.GRtime(x = t2, side = 2)
Axis(x = t, side = 1) #Axis also works
box() #complete the bounding box

#custom axes
plot(t2, 1:10, xaxt = "n")
axis.GRtime(at = pretty(t2, 20) , side = 1)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(GENEAread)
Loading required package: bitops
GENEAread 1.1.1 loaded

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GENEAread/GRtime.Rd_%03d_medium.png", width=480, height=480)
> ### Name: GRtime
> ### Title: Date time handling for the GENEAread package.
> ### Aliases: GRtime convert.time as.GRtime format.GRtime axis.GRtime
> ###   pretty.GRtime
> ### Keywords: methods
> 
> ### ** Examples
> 
> as.GRtime("00:01")
[1] 00:01
> #format is automatically set
> convert.time(1:10)
 [1] 00:01.000 00:02.000 00:03.000 00:04.000 00:05.000 00:06.000 00:07.000
 [8] 00:08.000 00:09.000 00:10.000
> convert.time(1:10*1000)
 [1] 00:16 00:33 00:50 01:06 01:23 01:40 01:56 02:13 02:30 02:46
> #we add a different default format
> convert.time(1:10*1000, "%H:%M:%OS3") -> t
> t
 [1] 00:16:40.000 00:33:20.000 00:50:00.000 01:06:40.000 01:23:20.000
 [6] 01:40:00.000 01:56:40.000 02:13:20.000 02:30:00.000 02:46:40.000
> str(t)
Classes 'GRtime', 'numeric'  atomic [1:10] 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
  ..- attr(*, "format")= chr "%H:%M:%OS3"
> #we override format with our own
> format(t, format = "%a %d/%m/%y %H:%M:%OS3")
 [1] "Thu 01/01/70 00:16:40.000" "Thu 01/01/70 00:33:20.000"
 [3] "Thu 01/01/70 00:50:00.000" "Thu 01/01/70 01:06:40.000"
 [5] "Thu 01/01/70 01:23:20.000" "Thu 01/01/70 01:40:00.000"
 [7] "Thu 01/01/70 01:56:40.000" "Thu 01/01/70 02:13:20.000"
 [9] "Thu 01/01/70 02:30:00.000" "Thu 01/01/70 02:46:40.000"
> 
> #plot calls axis.GRtime automatically. Notice
> #that the format attribute is used.
> plot(t, 1:10)
> #strip out the default format
> t2 = convert.time(t, format = NULL)
> plot(t2, 1:10)
> 
> #image plots are a bit more complex
> 
> Z = matrix(rnorm(100), 10)
> image(x = t, y = t2, z = Z, axes = FALSE)
> axis.GRtime(x = t2, side = 2)
> Axis(x = t, side = 1) #Axis also works
> box() #complete the bounding box
> 
> #custom axes
> plot(t2, 1:10, xaxt = "n")
> axis.GRtime(at = pretty(t2, 20) , side = 1)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>