Type Cast functions {PivotalR} | R Documentation

## Cast columns of `db.obj` objects to other types

### Description

Coerce `db.obj` object columns into other types. `col.types` displays the types of each column. `as.Date` converts to date (no time of day); `as.time` converts to time of day (no date); `as.timestamp` converts to both date and time; `as.interval` converts to time interval. `db.date.style` can display or set the date style for a particular connection.

### Usage

    ## S4 method for signature 'db.obj'
    as.integer(x, ...)

    ## S4 method for signature 'db.obj'
    as.character(x, array = TRUE, ...)

    ## S4 method for signature 'db.obj'
    as.double(x, ...)

    ## S4 method for signature 'db.obj'
    as.logical(x, ...)

    ## S4 method for signature 'db.obj'
    as.numeric(x, ...)

    ## S4 method for signature 'db.obj'
    as.Date(x, ...)

    db.date.style(conn.id = 1, set = NULL)

    as.time(x, ...)

    as.timestamp(x, ...)

    as.interval(x, ...)

    col.types(x)

### Arguments

`x` | A `db.obj` object. All columns of the object will be converted into the target type. If the column contains arrays, the array will be converted into an array of the target type.
`array` | A logical, default is `TRUE`. If `array` is `TRUE`, then an array column is converted into an array of strings. If `array` is `FALSE`, then an array column is converted into a string column, i.e. `array[1,2,3]` is casted into `'\{1,2,3\}'`.
`...` | further arguments passed to or from other methods This is currently not implemented.
`conn.id` | An integer, default is 1. The connection ID for the database connection.
`set` | A string, default is `NULL`. It can be `"us"` or `"european"`. If it is `NULL`, `db.date.style` displays the current date style in the connected database. Otherwise, it sets the date style for the connected database.

### Value

A `db.Rquery` object, which is a SQL query which combine all columns into an array.

`col.types` returns a vector of characters, which are the column types of `x`.

### Author(s)

Author: Predictive Analytics Team at Pivotal Inc.

Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io

### See Also

`by,db.obj-method` is usually used together with aggregate functions.

### Examples

    ## Not run:

    ## set up the database connection
    ## Assume that .port is port number and .dbname is the database name
    cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)

    x <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE)
    lk(x, 10)

    z <- as.integer(x > 1)
    lookat(z, 10)

    z <- as.integer(x[,2] == "M")
    lookat(z, 10)

    col.types(x)

    col.types(z)

    db.disconnect(cid, verbose = FALSE)

    ## End(Not run)

[Package PivotalR version 0.1.18.3.1 Index]