db.data.frame: Create a 'db.data.frame' object pointing to a table/view in...

Description Usage Arguments Value Author(s) See Also Examples

Description

This function creates an object of db.data.frame, which points to an existing table/view in the database. The operations that can be applied onto this class of objects are very similar to those of data.frame. No real data is loaded into R. The data transfered between the database and R is minimized, which is necessary when we deal with large data sets.

Usage

1
2
db.data.frame(x, conn.id = 1, key = character(0), verbose = TRUE,
is.temp = FALSE)

Arguments

x

A string. It is the name of an existing table/view in the database.

conn.id

An integer, default is 1. The ID number of the database connection where the table resides.

key

A string, default is character(0). The name of the primary key column. A primary key is a column in a table which must contain a unique value which can be used to identify each and every row of a table uniquely.

verbose

A logical, default is TRUE. Whether to print a short message when the object in the database is created.

is.temp

A logical, default is FALSE. Whether the existing table/view in the database is temporary.

Value

A db.data.frame object. More precisely, a db.table object if it points to an existing table in the database, and a db.view object if it points to an existing view in the database.

Author(s)

Author: Predictive Analytics Team at Pivotal Inc.

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

See Also

db.objects lists all tables and views in a database together with their schema.

db.existsObject tests whether a table/view exists in the database.

as.db.data.frame creates a db.data.frame from a data.frame, a data file or a db.Rquery.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## 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)

## create a table using as.db.data.frame
delete("abalone", conn.id = cid)
x <- as.db.data.frame(abalone, "abalone", conn.id = cid)

## create an object pointing to the table
y <- db.data.frame("abalone", conn.id = cid)

## x and y point to the same table
eql(x, y) # returns TRUE

## create an object pointing to a table in a schema
db.q("create schema myschema", conn.id = cid)
z <- as.db.data.frame(abalone, "myschema.abalone", conn.id = cid)
db.q("drop schema myschema cascade", conn.id = cid)

db.disconnect(cid, verbose = FALSE)

## End(Not run)

PivotalR documentation built on March 13, 2021, 1:06 a.m.