# 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)
## create a table from the example data.frame "abalone"
delete('abalone', conn.id = cid)
x <- as.db.data.frame(abalone, 'abalone', conn.id = cid, verbose = FALSE)
fit <- madlib.lm(rings ~ . - id - sex, data = x)
## create a db.Rquery object that has two columns
z <- cbind(x$rings, predict(fit, x))
## plot prediction v.s. real value
plot(lookat(z, 100))
## expand the db.obj
unlist(Map(function(x)
if (col.types(x) == "text")
paste(lk(unique(x)), collapse="-", sep="")
else
lk(mean(x))),
as.list(x))
## sum of all columns (excluding the 2nd column)
Reduce(function(left, right) left + right, as.list(x[-2]))
db.disconnect(cid, verbose = FALSE)
# }
Run the code above in your browser using DataLab