DSD_ReadDB | R Documentation |
A DSD class that reads a data stream from an open DB result set from a relational database with using R's data base interface (DBI).
DSD_ReadDB(
result,
k = NA,
outofpoints = c("warn", "ignore", "stop"),
description = NULL
)
## S3 method for class 'DSD_ReadDB'
close_stream(dsd, disconnect = TRUE, ...)
result |
An open DBI result set. |
k |
Number of true clusters, if known. |
outofpoints |
Action taken if less than
|
description |
a character string describing the data. |
dsd |
a stream. |
disconnect |
logical; disconnect from the database? |
... |
further arguments. |
This class provides a streaming interface for result sets from a data base
with via DBI::DBI. You need to connect to the data base and submit a SQL
query using DBI::dbGetQuery()
to obtain a result set. Make sure that your
query only includes the columns that should be included in the stream
(including class and outlier marking columns).
Closing and resetting the stream
Do not forget to clear the
result set and disconnect from the data base connection.
close_stream()
clears the query result with DBI::dbClearResult()
and the disconnects from the database with DBI::dbDisconnect()
. Disconnecting
can be prevented by calling close_stream()
with disconnect = FALSE
.
reset_stream()
is not available for this type of stream.
Additional information
If additional information is available (e.g., class information), then the SQL
statement needs to make sure that the columns have the appropriate name starting with .
.
See Examples section below.
An object of class DSD_ReadDB
(subclass of DSD_R, DSD).
Michael Hahsler
DBI::dbGetQuery()
Other DSD:
DSD()
,
DSD_BarsAndGaussians()
,
DSD_Benchmark()
,
DSD_Cubes()
,
DSD_Gaussians()
,
DSD_MG()
,
DSD_Memory()
,
DSD_Mixture()
,
DSD_NULL()
,
DSD_ReadStream()
,
DSD_Target()
,
DSD_UniformNoise()
,
DSD_mlbenchData()
,
DSD_mlbenchGenerator()
,
DSF()
,
animate_data()
,
close_stream()
,
get_points()
,
plot.DSD()
,
reset_stream()
### create a data base with a table with 3 Gaussians
if(require("RSQLite")) {
library("RSQLite")
con <- dbConnect(RSQLite::SQLite(), ":memory:")
points <- get_points(DSD_Gaussians(k = 3, d = 2), n = 110)
head(points)
dbWriteTable(con, "Gaussians", points)
### prepare a query result set. Make sure that the additional information
### column starts with .
res <- dbSendQuery(con, "SELECT X1, X2, `.class` AS '.class' FROM Gaussians")
res
### create a stream interface to the result set
stream <- DSD_ReadDB(res, k = 3)
stream
### get points
get_points(stream, n = 5)
plot(stream, n = 100)
### close stream clears the query and disconnects the database
close_stream(stream)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.