From 092288325090e9c97987a43ae6f390737aa37444 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Mon, 9 Feb 2015 17:20:21 +0100 Subject: [PATCH] Optimization in dump function (replaced some regular R function by data.table) --- R-package/R/xgb.dump.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R-package/R/xgb.dump.R b/R-package/R/xgb.dump.R index a0938ded1..7cb1c524a 100644 --- a/R-package/R/xgb.dump.R +++ b/R-package/R/xgb.dump.R @@ -46,12 +46,15 @@ xgb.dump <- function(model = NULL, fname = NULL, fmap = "", with.stats=FALSE) { stop("fmap: argument must be type character (when provided)") } - result <- .Call("XGBoosterDumpModel_R", model, fmap, as.integer(with.stats), PACKAGE = "xgboost") + dt <- .Call("XGBoosterDumpModel_R", model, fmap, as.integer(with.stats), PACKAGE = "xgboost") %>% fread + + setnames(dt, "Content") if(is.null(fname)) { - return(str_split(result, "\n") %>% unlist %>% str_replace("^\t+","") %>% Filter(function(x) x != "", .)) + result <- dt[Content != "0"][,Content := str_replace(Content, "^\t+", "")][Content != ""][,paste(Content)] + return(result) } else { - result %>% str_split("\n") %>% unlist %>% Filter(function(x) x != "", .) %>% writeLines(fname) + result <- dt[Content != "0"][Content != ""][,paste(Content)] %>% writeLines(fname) return(TRUE) } }