| Line 35... |
Line 35... |
| 35 |
stopifnot(class(sv) == "sqlite.vector", has.typeSvec(sv, class(df[[j]])[1]))
|
35 |
stopifnot(class(sv) == "sqlite.vector", has.typeSvec(sv, class(df[[j]])[1]))
|
| 36 |
if (length(sv) != nrows) stop("Unexpected # of rows for col", j, "\n")
|
36 |
if (length(sv) != nrows) stop("Unexpected # of rows for col", j, "\n")
|
| 37 |
for (i in 1:nrows)
|
37 |
for (i in 1:nrows)
|
| 38 |
if (sv[i] != df[i,j])
|
38 |
if (sv[i] != df[i,j])
|
| 39 |
stop("Not equal on row ", i, ", col ", j, "\n")
|
39 |
stop("Not equal on row ", i, ", col ", j, "\n")
|
| - |
|
40 |
all.equal(sv[c(T,F,F)], df[c(T,F,F),j])
|
| 40 |
}
|
41 |
}
|
| 41 |
|
42 |
|
| 42 |
# test names.sqlite.data.frame, [[.sqlite.data.frame (name arg), ...
|
43 |
# test names.sqlite.data.frame, [[.sqlite.data.frame (name arg), ...
|
| 43 |
if (with.names) for (j in names(df)) {
|
44 |
if (with.names) for (j in names(df)) {
|
| 44 |
sv <- sdf[[j]]; # test sqlite.vector
|
45 |
sv <- sdf[[j]]; # test sqlite.vector
|
| Line 127... |
Line 128... |
| 127 |
# test sdf indexers
|
128 |
# test sdf indexers
|
| 128 |
compareSdfToDf(iris.sdf, iris)
|
129 |
compareSdfToDf(iris.sdf, iris)
|
| 129 |
#compareSdfToDf(u2.sdf, attenu) # problem with factors
|
130 |
#compareSdfToDf(u2.sdf, attenu) # problem with factors
|
| 130 |
stopifnot(all.equal(unlist(iris.sdf),unlist(iris.sdf[])),
|
131 |
stopifnot(all.equal(unlist(iris.sdf),unlist(iris.sdf[])),
|
| 131 |
all.equal(unlist(iris.sdf),unlist(iris.sdf[,])))
|
132 |
all.equal(unlist(iris.sdf),unlist(iris.sdf[,])))
|
| 132 |
tmp <- iris.sdf[1]
|
133 |
tmp <- iris.sdf[1] # sdf w/ ncol=1
|
| 133 |
stopifnot(nrow(tmp) == nrow(iris.sdf),
|
134 |
stopifnot(nrow(tmp) == nrow(iris.sdf),
|
| 134 |
names(tmp) == names(iris.sdf)[1],
|
135 |
names(tmp) == names(iris.sdf)[1],
|
| 135 |
all.equal(tmp[,1], iris.sdf[,1]))
|
136 |
all.equal(tmp[,1], iris.sdf[,1]))
|
| 136 |
|
137 |
|
| 137 |
|
138 |
|
| Line 146... |
Line 147... |
| 146 |
all.equal(quantile(iris.sdf[,3]), quantile(iris[,3])),
|
147 |
all.equal(quantile(iris.sdf[,3]), quantile(iris[,3])),
|
| 147 |
all.equal(sapply(iris.sdf[,1:4],mean), sapply(iris[,1:4],mean)))
|
148 |
all.equal(sapply(iris.sdf[,1:4],mean), sapply(iris[,1:4],mean)))
|
| 148 |
|
149 |
|
| 149 |
stopifnot(sapply(iris.sdf[,1:4],sum) == sapply(iris[,1:4],sum))
|
150 |
stopifnot(sapply(iris.sdf[,1:4],sum) == sapply(iris[,1:4],sum))
|
| 150 |
|
151 |
|
| - |
|
152 |
|
| - |
|
153 |
# test [<-.sqlite.vector
|
| - |
|
154 |
ref <- data.frame(
|
| - |
|
155 |
integer=1:10, real=as.real(1:10),
|
| - |
|
156 |
logical=rep(c(T,F,T),length.out=10),
|
| - |
|
157 |
character=I(c("one", "two", "three", "four", "five",
|
| - |
|
158 |
"six", "seven", "eight", "nine", "ten")))
|
| - |
|
159 |
ref.sdf <- sqlite.data.frame(ref)
|
| - |
|
160 |
.assign <- function (svec, idx, values, eqvalues=values) {
|
| - |
|
161 |
idxlen <- if (is.logical(idx)) sum(rep(idx, length.out=length(svec))) else length(idx)
|
| - |
|
162 |
if (is.logical(idx)) idx <- rep(idx, length.out=length(svec))
|
| - |
|
163 |
if (length(values) != idxlen)
|
| - |
|
164 |
values <- rep(values, length.out=idxlen)
|
| - |
|
165 |
if (length(eqvalues) != idxlen)
|
| - |
|
166 |
eqvalues <- rep(eqvalues, length.out=idxlen)
|
| - |
|
167 |
svec[idx] <- values
|
| - |
|
168 |
all.equal(svec[idx], eqvalues)
|
| - |
|
169 |
}
|
| - |
|
170 |
|
| - |
|
171 |
## test real <- real, int, logical
|
| - |
|
172 |
col = ref.sdf[["real"]]
|
| - |
|
173 |
stopifnot(.assign(col, 1, 25),
|
| - |
|
174 |
.assign(col, c(1,3,5,7,9), 100),
|
| - |
|
175 |
.assign(col, c(1,3,5,7,9), c(25, 100)),
|
| - |
|
176 |
.assign(col, c(2,4,6,8,10), c(T,F,T), as.real(c(T,F,T))), # w/ logicals
|
| - |
|
177 |
.assign(col, c(4,5,6,7,8), 1:5, as.real(1:5)), # w/ ints
|
| - |
|
178 |
.assign(col, c(T,F), 1:5, as.real(1:5)))
|
| - |
|
179 |
|
| - |
|
180 |
# test int <- int, logical
|
| - |
|
181 |
col = ref.sdf[["integer"]]
|
| - |
|
182 |
stopifnot(.assign(col, 1, as.integer(25)),
|
| - |
|
183 |
.assign(col, c(1,3,5,7,9), as.integer(100)),
|
| - |
|
184 |
.assign(col, c(1,3,5,7,9), as.integer(c(25, 100))),
|
| - |
|
185 |
.assign(col, c(2,4,6,8,10), c(T,F,T), as.integer(c(1,0,1))), # w/ logicals
|
| - |
|
186 |
.assign(col, c(4,5,6,7,8), 1:5), # w/ ints
|
| - |
|
187 |
.assign(col, c(T,F), 1:5))
|
| - |
|
188 |
|
| - |
|
189 |
# test logical <- logical
|
| - |
|
190 |
col = ref.sdf[["logical"]]
|
| - |
|
191 |
stopifnot(.assign(col, 1, F),
|
| - |
|
192 |
.assign(col, c(1,3,5,7,9), F),
|
| - |
|
193 |
.assign(col, c(F,T), T))
|
| - |
|
194 |
|
| - |
|
195 |
# test character <- character, real, int, logical
|
| - |
|
196 |
col = ref.sdf[["character"]]
|
| - |
|
197 |
stopifnot(.assign(col, 1, "isa"),
|
| - |
|
198 |
.assign(col, c(1,3,5,7,9), c("uno", "tatlo", "lima", "pito", "syam")),
|
| - |
|
199 |
.assign(col, 1, 25, "25"),
|
| - |
|
200 |
.assign(col, 1, 3/4, "0.75"), # w/ reals
|
| - |
|
201 |
.assign(col, 1:5, as.integer(3), "3"), # w/ integers
|
| - |
|
202 |
.assign(col, 4:8, c(T,F), c("TRUE","FALSE"))) # w/ logicals
|
| 151 |
# test sdfImportDBI
|
203 |
# test sdfImportDBI
|
| 152 |
#if (require(RSQLite)) {
|
204 |
#if (require(RSQLite)) {
|
| 153 |
# dr <- SQLite()
|
205 |
# dr <- SQLite()
|
| 154 |
# con <- dbConnect(dr, dbname="example.db")
|
206 |
# con <- dbConnect(dr, dbname="example.db")
|
| 155 |
# i1 <- sdfImportDBI(con, "select * from iris")
|
207 |
# i1 <- sdfImportDBI(con, "select * from iris")
|