@@ -498,6 +498,12 @@ h2o.ddply <- function (.data, .variables, .fun = NULL, ..., .progress = 'none')
498
498
if ( any(bad ) ) stop( sprintf(' can\' t recognize .variables %s' , paste(vars [bad ], sep = ' ,' )) )
499
499
500
500
fun_name <- mm [[ ' .fun' ]]
501
+
502
+ if (identical(as.list(substitute(.fun ))[[1 ]], quote(`function` ))) {
503
+ h2o.addFunction(.data @ h2o , .fun , " anonymous" )
504
+ fun_name <- " anonymous"
505
+ }
506
+
501
507
exec_cmd <- sprintf(' ddply(%s,c(%s),%s)' , .data @ key , paste(idx , collapse = ' ,' ), as.character(fun_name ))
502
508
res <- .h2o.__exec2(.data @ h2o , exec_cmd )
503
509
.h2o.exec2(res $ dest_key , h2o = .data @ h2o , res $ dest_key )
@@ -520,7 +526,7 @@ h2o.addFunction <- function(object, fun, name){
520
526
if ( class(name ) != ' character' ) stop(' name must be a name' )
521
527
fun_name <- name
522
528
} else {
523
- fun_name <- match.call()[[' fun' ]]
529
+ fun_name <- " anonymous " # fun_name <- match.call()[['fun']]
524
530
}
525
531
src <- paste(deparse(fun ), collapse = ' \n ' )
526
532
exec_cmd <- sprintf(' %s <- %s' , as.character(fun_name ), src )
@@ -1108,15 +1114,10 @@ head.H2OParsedData <- function(x, n = 6L, ...) {
1108
1114
stopifnot(length(n ) == 1L )
1109
1115
n <- ifelse(n < 0L , max(numRows + n , 0L ), min(n , numRows ))
1110
1116
if (n == 0 ) return (data.frame ())
1111
-
1112
- x.slice = as.data.frame(x [seq_len(n ),])
1113
- # if(ncol(x) > .MAX_INSPECT_COL_VIEW)
1114
- # warning(x@key, " has greater than ", .MAX_INSPECT_COL_VIEW, " columns. This may take awhile...")
1115
- # res = .h2o.__remoteSend(x@h2o, .h2o.__HACK_LEVELS2, source = x@key, max_ncols = .Machine$integer.max)
1116
- # for(i in 1:ncol(x)) {
1117
- # if(!is.null(res$levels[[i]]))
1118
- # x.slice[,i] <- factor(x.slice[,i], levels = res$levels[[i]])
1119
- # }
1117
+
1118
+ tmp_head <- x [seq_len(n ),]
1119
+ x.slice = as.data.frame(tmp_head )
1120
+ h2o.rm(tmp_head @ h2o , tmp_head @ key )
1120
1121
return (x.slice )
1121
1122
}
1122
1123
@@ -1127,16 +1128,10 @@ tail.H2OParsedData <- function(x, n = 6L, ...) {
1127
1128
if (n == 0 ) return (data.frame ())
1128
1129
1129
1130
idx <- seq.int(to = nrx , length.out = n )
1130
- x.slice <- as.data.frame(x [idx ,])
1131
+ tmp_tail <- x [idx ,]
1132
+ x.slice <- as.data.frame(tmp_tail )
1133
+ h2o.rm(tmp_tail @ h2o , tmp_tail @ key )
1131
1134
rownames(x.slice ) <- idx
1132
-
1133
- # if(ncol(x) > .MAX_INSPECT_COL_VIEW)
1134
- # warning(x@key, " has greater than ", .MAX_INSPECT_COL_VIEW, " columns. This may take awhile...")
1135
- # res = .h2o.__remoteSend(x@h2o, .h2o.__HACK_LEVELS2, source = x@key, max_ncols = .Machine$integer.max)
1136
- # for(i in 1:ncol(x)) {
1137
- # if(!is.null(res$levels[[i]]))
1138
- # x.slice[,i] <- factor(x.slice[,i], levels = res$levels[[i]])
1139
- # }
1140
1135
return (x.slice )
1141
1136
}
1142
1137
@@ -1254,34 +1249,83 @@ screeplot.H2OPCAModel <- function(x, npcs = min(10, length(x@model$sdev)), type
1254
1249
as.logical(.h2o.__unop2(" canBeCoercedToLogical" , vec ))
1255
1250
}
1256
1251
1257
- setMethod ("ifelse ", signature(test="H2OParsedData", yes="ANY", no="ANY"), function(test, yes, no) {
1258
- if (! (is.numeric(yes ) || class(yes ) == " H2OParsedData" ) || ! (is.numeric(no ) || class(no ) == " H2OParsedData" ))
1259
- stop(" Unimplemented" )
1260
- if (! test @ logic && ! .canBeCoercedToLogical(test )) stop(test @ key , " is not a H2O logical data type" )
1261
- .h2o.__multop2(" ifelse" , test , yes , no )
1262
- })
1263
-
1264
- setMethod ("ifelse ", signature(test="logical", yes="H2OParsedData", no="numeric"), function(test, yes, no) {
1265
- if (length(test ) > 1 ) stop(" test must be a single logical value" )
1266
- .h2o.__multop2(" ifelse" , as.numeric(test ), yes , no )
1267
- })
1268
-
1269
- setMethod ("ifelse ", signature(test="logical", yes="numeric", no="H2OParsedData"), function(test, yes, no) {
1270
- if (length(test ) > 1 ) stop(" test must be a single logical value" )
1271
- .h2o.__multop2(" ifelse" , as.numeric(test ), yes , no )
1272
- })
1252
+ .check.ifelse.conditions <-
1253
+ function (test , yes , no , type ) {
1254
+ if (type == " test" ) {
1255
+ return (class(test ) == " H2OParsedData"
1256
+ && (is.numeric(yes ) || class(yes ) == " H2OParsedData" || is.logical(yes ))
1257
+ && (is.numeric(no ) || class(no ) == " H2OParsedData" || is.logical(no ))
1258
+ && (test @ logic || .canBeCoercedToLogical(test )))
1259
+ }
1260
+ }
1273
1261
1274
- setMethod ("ifelse ", signature(test="logical", yes="H2OParsedData", no="H2OParsedData"), function(test, yes, no) {
1275
- if (length(test ) > 1 ) stop(" test must be a single logical value" )
1276
- .h2o.__multop2(" ifelse" , as.numeric(test ), yes , no )
1277
- })
1262
+ ifelse <-
1263
+ function (test , yes , no )
1264
+ {
1265
+ if (.check.ifelse.conditions(test , yes , no , " test" )) {
1266
+ if (is.logical(yes )) yes <- as.numeric(yes )
1267
+ if (is.logical(no )) no <- as.numeric(no )
1268
+ return (.h2o.__multop2(" ifelse" , test , yes , no ))
1269
+
1270
+ } else if ( class(yes ) == " H2OParsedData" && class(test ) == " logical" ) {
1271
+ if (is.logical(yes )) yes <- as.numeric(yes )
1272
+ if (is.logical(no )) no <- as.numeric(no )
1273
+ return (.h2o.__multop2(" ifelse" , as.numeric(test ), yes , no ))
1274
+
1275
+ } else if (class(no ) == " H2OParsedData" && class(test ) == " logical" ) {
1276
+ if (is.logical(yes )) yes <- as.numeric(yes )
1277
+ if (is.logical(no )) no <- as.numeric(no )
1278
+ return (.h2o.__multop2(" ifelse" , as.numeric(test ), yes , no ))
1279
+ }
1280
+ if (is.atomic(test ))
1281
+ storage.mode(test ) <- " logical"
1282
+ else test <- if (isS4(test ))
1283
+ as(test , " logical" )
1284
+ else as.logical(test )
1285
+ ans <- test
1286
+ ok <- ! (nas <- is.na(test ))
1287
+ if (any(test [ok ]))
1288
+ ans [test & ok ] <- rep(yes , length.out = length(ans ))[test &
1289
+ ok ]
1290
+ if (any(! test [ok ]))
1291
+ ans [! test & ok ] <- rep(no , length.out = length(ans ))[! test &
1292
+ ok ]
1293
+ ans [nas ] <- NA
1294
+ ans
1295
+ }
1278
1296
1279
- setMethod ("levels ", "H2OParsedData", function(x) {
1280
- # if(ncol(x) != 1) return(NULL)
1281
- if (ncol(x ) != 1 ) stop(" Can only retrieve levels of one column." )
1282
- res = .h2o.__remoteSend(x @ h2o , .h2o.__HACK_LEVELS2 , source = x @ key , max_ncols = .Machine $ integer.max )
1283
- res $ levels [[1 ]]
1284
- })
1297
+ # setMethod("ifelse", signature(test="H2OParsedData", yes="ANY", no="ANY"), function(test, yes, no) {
1298
+ # if(!(is.numeric(yes) || class(yes) == "H2OParsedData") || !(is.numeric(no) || class(no) == "H2OParsedData"))
1299
+ # stop("Unimplemented")
1300
+ # if(!test@logic && !.canBeCoercedToLogical(test)) stop(test@key, " is not a H2O logical data type")
1301
+ # h2o.exec(ifelse(test, yes, no))
1302
+ # # .h2o.__multop2("ifelse", eval(test), yes, no)
1303
+ # })
1304
+ # #
1305
+ # setMethod("ifelse", signature(test="logical", yes="H2OParsedData", no="ANY"), function(test, yes, no) {
1306
+ # if(length(test) > 1) stop("test must be a single logical value")
1307
+ # h2o.exec(ifelse(test, yes, no))
1308
+ # # .h2o.__multop2("ifelse", as.numeric(test), eval(yes), no)
1309
+ # })
1310
+ #
1311
+ # setMethod("ifelse", signature(test="logical", yes="ANY", no="H2OParsedData"), function(test, yes, no) {
1312
+ # if(length(test) > 1) stop("test must be a single logical value")
1313
+ # h2o.exec(ifelse(test, yes, no))
1314
+ # # .h2o.__multop2("ifelse", as.numeric(test), yes, eval(no))
1315
+ # })
1316
+ #
1317
+ # setMethod("ifelse", signature(test="logical", yes="H2OParsedData", no="H2OParsedData"), function(test, yes, no) {
1318
+ # if(length(test) > 1) stop("test must be a single logical value")
1319
+ # h2o.exec(ifelse(test, yes, no))
1320
+ # # .h2o.__multop2("ifelse", as.numeric(test), eval(yes), eval(no))
1321
+ # })
1322
+ #
1323
+ # setMethod("levels", "H2OParsedData", function(x) {
1324
+ # # if(ncol(x) != 1) return(NULL)
1325
+ # if(ncol(x) != 1) stop("Can only retrieve levels of one column.")
1326
+ # res = .h2o.__remoteSend(x@h2o, .h2o.__HACK_LEVELS2, source = x@key, max_ncols = .Machine$integer.max)
1327
+ # res$levels[[1]]
1328
+ # })
1285
1329
1286
1330
# ----------------------------- Work in Progress -------------------------------#
1287
1331
# TODO: Need to change ... to environment variables and pass to substitute method,
0 commit comments