Rev 3324 | Rev 3471 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{sqlite.data.frame}\alias{sqlite.data.frame}\alias{sdf}\title{SQLite Data Frame}\description{ Creates an sqlite data frame (SDF) from ordinary data frames. }\usage{sqlite.data.frame(x, name=NULL)}\arguments{\item{x}{The object to be coerced into a data frame which is then stored in aSQLite database. \code{as.data.frame} is called first on x before creatingthe SDF database. }\item{name}{The internal name of the SDF. If none is provided, a genericname \emph{data}<n> is used (e.g. data1, data2, etc). Each SDF should have a uniqueinternal name and also be a valid R symbol. Numbers are appended to names in case of duplicates,e.g. if name arg is \emph{iris}, and it already exists, then thenew SDF will have a name \emph{iris1}. If it still exists, then the namewill be \emph{iris2}, and so on. }}\details{SQLite data frames (SDF's) are data frames whose data are stored in a SQLite database.SQLite is an open source, powerful (considering its size), light weight data base engine.It stores each database (composed of tables, indices, etc.) in a single file. Since asingle SDF occupies a whole database, each SDF will be contained in a single file.Each SDF file contains the following tables:\itemize{\item{sdf_attributes}{a key-value table that contains the SDF attributes. Currently,only \emph{name} is used representing the SDF's internal name.}\item{sdf_data}{contains the actual data. Factors and ordered variables are stored asintegers. Their levels are stored in other tables. Numeric (real) are stored as double,characters as text and integers as int's. Currently, complex numbers are not supported.Column names correspond exactly to the variable names of the ordinary data frames. E.g.Petal.Length will have a column name Petal.Length in the table. This is possiblebecause SQLite allows almost any kind of column name as long as it is quoted bysquare brakets ([ ]). You're on your own if you try to be a smartass on this. Also,an extra column named \emph{row name} (with the space between the words), of typetext is used to store the data frame row names is set as the table's primary key.So please don't use \emph{row name} as a variable name.}\item{[factor <colname>] and [ordered <colname>]}{stores the levels and level labelsfor each factor variable in the SDF. One such table will be created for everyfactor or ordered var, even if two variables share the same level labels. Besidesstoring the level data, it is used to mark a column as being a factor.}}SDF's are managed in a workspace separate from R's. When SQLiteDF is loaded, it searchesfor the file \code{workspace.db} in the current working directory. This file containsa list of SDF's created/used in the previous session (i.e. SQLiteDF sessions are automaticallysaved), including their full and relative path and attach information.Workspace is managed using the SQLite engineby opening \code{workspace.db} as the main database and then attaching (SQLite's attach) the SDF's.Unfortunately, the number of attached databases is limited to 31 (actually 32, but 1 is reservedfor the temp db). Therefore, SDF's are \emph{scored} according to the number of timesit has been used. When the maximum allowed attachment is reached, the least used attachedSDF's is detached and the needed one is attached in its place. The packaged SQLite3 static libraryhas been modified to have 31 maximum attachments, because the default is 10.Back to when SQLiteDF is loaded, after opening \code{workspace.db}, the SDF's stored in the listare sorted according to their number of uses in the previous session and then thefirst 30 are attached. The relative path is used for finding the SDF file. If the filecannot be found, it is deleted from the SQLiteDF workspace (with a warning message). Thescores are then all reset.A sqlite.data.frame object is a list a single element:\itemize{\item{iname}{the internal name of the SDF.}}and the following attributes:\itemize{\item{class}{The S3 class vector \code{c("sqlite.data.frame", "data.frame")}}\item{row.names}{A sqlite.vector of mode character containing the row names of the SDF}}}\value{A S3 object representing the SDF. The SDF database will be created in the same directorywith file name derived by appending the extension \emph{db} to the passed internalname, or the default internal name if none is provided.}\author{Miguel A. R. Manese}\note{The full path is used to avoid attaching the same db which may have different relative pathafter the user changes directory after loading SQLiteDF (see \code{attachSdf}.}\seealso{\code{\link[SQLiteDF]{lsSdf}}\code{\link[SQLiteDF]{getSdf}}\code{\link[SQLiteDF]{attachSdf}}\code{\link[SQLiteDF]{detachSdf}}}\examples{library(datasets)iris.sdf <- sqlite.data.frame(iris)names(iris.sdf)class(iris.sdf)iris.sdf$Petal.Length[1:10]iris.sdf[["Petal.Length"]][1:10]iris.sdf[1,c(TRUE,FALSE)]#apply(iris.sdf[1:4], 2, mean)}