
Last chance! 50% off unlimited learning
Sale ends in
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.
arraydb.to.arrayr(str, type = "double", ...)
A vector of strings, or a single string, that has multiple elements
in it and deliited by ","
.
The type of the return value of this function. Default is
"double"
. It can be "character"
, "double"
,
"logical"
, "integer"
,
"numeric"
etc. All types other than "character"
,
"logical"
and
"integer"
will be treated as "numeric"
.
Further arguments passed to or from other methods. Currently, no more parameters can be passed and this is kept for backwards compatibility.
A two dimensional array, whose element's type is decided by the
function argument type
.
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.
lk
or link{lookat}
extracts the data of a table
# NOT RUN {
<!-- %% @test .port Database port number -->
<!-- %% @test .dbname Database name -->
## 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)
# }
Run the code above in your browser using DataLab