From c9fba4f3132f6e8e28bd0d3b4f9ca57e5a74b186 Mon Sep 17 00:00:00 2001 From: Maximilian Muecke Date: Fri, 2 Aug 2024 21:23:49 +0200 Subject: [PATCH] perf: set use.names to false in unlist where applicable --- R/Design.R | 2 +- R/Domain_methods.R | 2 +- R/ParamSet.R | 8 ++++---- R/ParamSetCollection.R | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/Design.R b/R/Design.R index 41a6b425..07deea8d 100644 --- a/R/Design.R +++ b/R/Design.R @@ -100,7 +100,7 @@ Design = R6Class("Design", # we need to make sure that every param has a (maybe empty) row in the graph table fillin = data.table(id = ps$ids(), parents = list(character(0L))) graph = rbind(graph, fillin[fillin$id %nin% graph$id, ]) - graph = graph[, list("parents" = list(unlist(get("parents")))), by = "id"] + graph = graph[, list("parents" = list(unlist(get("parents"), use.names = FALSE))), by = "id"] topo = topo_sort(graph) pids_sorted = topo$id storage_types = ps$storage_type diff --git a/R/Domain_methods.R b/R/Domain_methods.R index 2e149196..0ae3b2cf 100644 --- a/R/Domain_methods.R +++ b/R/Domain_methods.R @@ -175,7 +175,7 @@ check_domain_vectorize = function(ids, values, checker, more_args = list()) { if (isTRUE(ch)) NULL else sprintf("%s: %s", id, ch) }) } - errors = unlist(errors) + errors = unlist(errors, use.names = FALSE) if (!length(errors)) return(TRUE) str_collapse(errors, sep = "\n") } diff --git a/R/ParamSet.R b/R/ParamSet.R index db2a9753..7fd9dfdc 100644 --- a/R/ParamSet.R +++ b/R/ParamSet.R @@ -81,7 +81,7 @@ ParamSet = R6Class("ParamSet", # fastest way to init a data.table private$.tags = structure(list( id = rep(paramtbl$id, lengths(paramtbl$.tags)), - tag = unlist(paramtbl$.tags) + tag = unlist(paramtbl$.tags, use.names = FALSE) ), class = c("data.table", "data.frame") ) } else { @@ -542,7 +542,7 @@ ParamSet = R6Class("ParamSet", } msg }) - errors = unlist(errors) + errors = unlist(errors, use.names = FALSE) if (!length(errors)) return(TRUE) str_collapse(errors, sep = "\n") }, @@ -816,7 +816,7 @@ ParamSet = R6Class("ParamSet", deps = self$deps if (nrow(deps)) { # add a nice extra charvec-col to the tab, which lists all parents-ids on = NULL - dd = deps[, list(parents = list(unlist(on))), by = "id"] + dd = deps[, list(parents = list(unlist(on, use.names = FALSE))), by = "id"] d = merge(d, dd, by = "id", all.x = TRUE) } v = named_list(d$id) # add values to last col of print-dt as list col @@ -863,7 +863,7 @@ ParamSet = R6Class("ParamSet", assert_list(v, any.missing = FALSE, types = "character") if (length(v)) assert_names(names(v), permutation.of = private$.params$id) # as.character() to handle empty lists and resulting NULL-valures. - private$.tags = data.table(id = rep(as.character(names(v)), map_int(v, length)), tag = as.character(unlist(v)), key = "id") + private$.tags = data.table(id = rep(as.character(names(v)), map_int(v, length)), tag = as.character(unlist(v, use.names = FALSE)), key = "id") setindexv(private$.tags, "tag") # return value with original ordering return(v) diff --git a/R/ParamSetCollection.R b/R/ParamSetCollection.R index df342b0c..5ea93599 100644 --- a/R/ParamSetCollection.R +++ b/R/ParamSetCollection.R @@ -169,7 +169,7 @@ ParamSetCollection = R6Class("ParamSetCollection", inherit = ParamSet, } if (tag_sets && n != "") paramtbl[, .tags := map(.tags, function(x) c(x, sprintf("set_%s", n)))] if (tag_params) paramtbl[, .tags := pmap(list(.tags, original_id), function(x, n) c(x, sprintf("param_%s", n)))] - newtags = paramtbl[, .(tag = unique(unlist(.tags))), by = "id"] + newtags = paramtbl[, .(tag = unique(unlist(.tags, use.names = FALSE))), by = "id"] if (nrow(newtags)) { private$.tags = setkeyv(rbind(private$.tags, newtags), "id") }