From 10f755e055133f35c0b46e913d44d31577eafc63 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Fri, 9 Jan 2015 11:06:56 +0100 Subject: [PATCH] only replace tabulation which begins a line (avoid wrong replacement in feature name) --- R-package/R/xgb.dump.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R-package/R/xgb.dump.R b/R-package/R/xgb.dump.R index 0d7e79f31..7049257f8 100644 --- a/R-package/R/xgb.dump.R +++ b/R-package/R/xgb.dump.R @@ -40,8 +40,10 @@ xgb.dump <- function(model, fname = NULL, fmap = "", with.stats=FALSE) { } result <- .Call("XGBoosterDumpModel_R", model, fmap, as.integer(with.stats), PACKAGE = "xgboost") - if(is.null(fname)) return(str_split(result, "\n") %>% unlist %>% str_replace_all("\t"," ") %>% Filter(function(x) x != "", .)) - - writeLines(result, fname) - TRUE -} + if(is.null(fname)) { + return(str_split(result, "\n") %>% unlist %>% str_replace("^\t+","") %>% Filter(function(x) x != "", .)) + } else { + writeLines(result, fname) + return(TRUE) + } +} \ No newline at end of file