Description Usage Arguments Details Value Note Author(s) See Also Examples
An array object in database is converted to a string when passed into
R, for example '\{1.2, 3.4, 5.7\}', and this function can convert the
string to an array in R, for example c(1.2, 3.4, 5.7). This function
can also convert a vector of such strings into a two-dimensional
array.
1 | arraydb.to.arrayr(str, type = "double", ...)
|
str |
A vector of strings, or a single string, that has multiple elements
in it and deliited by |
type |
The type of the return value of this function. Default is
|
... |
Further arguments passed to or from other methods. Currently, no more parameters can be passed and this is kept for backwards compatibility. |
When R reads in data from a table in the database, the result is a
data.frame object. However, if the orginal data table has a column
which is the array type, the array is automatically converted into a
string and data.frame object has a corresponding column of strings,
each of which starts with "{" and ends with "\}",
and all the original
array elements are casted into strings delimited by ",".
For example, the array in database array['ab', 'c d', '"axx, t"']
becomes a string in R '{ab, c d, \"axx, t\"}'.
This function deals with such strings and turn them into faimiliar arrays that users can directly use.
A two dimensional array, whose element's type is decided by the
function argument type.
(1) The returned value is a two dimensional array, even if str
is a single string.
(2) Although this function is for the strings extracted from database,
it can actually deal with strings like "a, b, c", which do not start
or end with curly brackets.
Author: Predictive Analytics Team at Pivotal Inc.
Maintainer: Frank McQuillan, Pivotal Inc. fmcquillan@pivotal.io
lk or link{lookat} extracts the data of a table
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 26 27 | ## 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)
## Example 1 ----------
str <- '{1.2, 3.4, 5.6}'
arraydb.to.arrayr(str, "double") # c(1.2, 3.4, 5.6)
str <- '{a, b, "c, d"}'
arraydb.to.arrayr(str, "character") # c("a", "b", "\"c, d\"")
## Example 2 ----------
## table_in_database has a column of arrays
x <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE)
x$col.array <- db.array(x[,3:10])
dat <- lk(x, nrows = 50, array = FALSE) # extract the actual data
arraydb.to.arrayr(dat$col.array, "double") # an array of 50 rows
## ----------------------------------------------------------------------
db.disconnect(cid, verbose = FALSE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.