preview {PivotalR} | R Documentation |
These functions read the actual data from a database table or operation, returning a data.frame
or other object as appropriate. lookat
and lk
are actually the same.
lookat(x, nrows = 100, array = TRUE, conn.id = 1, drop = TRUE) lk(x, nrows = 100, array = TRUE, conn.id = 1, drop = TRUE) ## S3 method for class 'db.table' as.data.frame(x, row.names = NULL, optional = FALSE, nrows = NULL, stringsAsFactors = default.stringsAsFactors(), array = TRUE, ...) ## S3 method for class 'db.view' as.data.frame(x,row.names=NULL, optional=FALSE, nrows = NULL, stringsAsFactors = default.stringsAsFactors(), array = TRUE, ...) ## S3 method for class 'db.Rquery' as.data.frame(x, row.names = NULL, optional = FALSE, nrows = NULL, stringsAsFactors = default.stringsAsFactors(), array = TRUE, ...)
x |
A |
conn.id |
An integer, the ID of the connection where the table resides. |
nrows |
An integer, how many rows of data to retrieve. If it is
|
array |
Logical, default is |
stringsAsFactors |
Logical, whether character variables should be converted to factors. |
drop |
Whether to coerce single-column tables to a vector of the appropriate class. |
row.names,optional,... |
For compatibility with the |
When x
is a db.data.frame
object, this
function reads the data in a table or view in the connected database.
When x
is a db.Rquery
object, this
function reads the result of some operations on a
db.data.frame
object.
When x
is a db.Rcrossprod
object, this function output a matrix to R. If the matrix is symmetric,
it is returned as dspMatrix
. Otherwise, it is
returned as dgeMatrix
. If there are multiple
matrices in x
, a list is returned and each element of the list
is a matrix.
The as.data.frame
method calls lookat
with nrows = NULL
to perform the conversion to a data frame. In this case drop
is set to FALSE
, ie the result will always be a data frame.
For db.data.frame
and db.Rquery
objects, a data frame. Each column in the table becomes a column
of the returned data.frame
. A column of arrays is converted into
a column of strings, see arraydb.to.arrayr
for more
details. Single-column tables created with lookat
or lk
will be coerced to a vector if drop == TRUE
.
For db.Rcrossprod
objects, a matrix or list of matrix objects as appropriate (see above).
Author: Predictive Analytics Team at Pivotal Inc.
Hong Ooi, Pivotal Inc. hooi@pivotal.io wrote the
as.data.frame
methods.
Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io
arraydb.to.arrayr
convert strings extracted form
database into arrays.
## 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) ## create a table from the example data.frame "abalone" x <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE) ## preview of a table lk(x, nrows = 10) # extract 10 rows of data ## do some operations and preview the result y <- (x[,1:2] + 1.2) * 2 lk(y, 20) ## table abalone has a column named "id" lk(sort(x, INDICES = x$id), 20) # the preview is ordered by "id" value ## use as.data.frame as.data.frame(x, 10) db.disconnect(cid, verbose = FALSE) ## End(Not run)