Generate a name with a prefix disjoint from a set of names

novelName(prefix, names)

Arguments

prefix

character, desired prefix

names

character list of names to avoid

Value

new name disjoint from set of names

Examples

# basic op novelName('b', c('a', 'b', 'c'))
#> [1] "b_1"
# complex application (converting logistic # links to probabilities). d <- data.frame( exampleId = c(1, 1, 2, 2), resultLabel = c('a', 'b' , 'a', 'b'), linkValue = c(-5, 2, -2, -1), stringsAsFactors = FALSE) totColName <- novelName('t', colnames(d)) d ->.; mutate_se(., c(totColName := "exp(linkValue)")) ->.; group_by_se(., "exampleId") ->.; mutate_se(., c("probability" := paste0(totColName, '/sum(', totColName, ')'))) ->.; deselect(., totColName)
#> # A tibble: 4 x 4 #> # Groups: exampleId [2] #> exampleId resultLabel linkValue probability #> <dbl> <chr> <dbl> <dbl> #> 1 1 a -5 0.000911 #> 2 1 b 2 0.999 #> 3 2 a -2 0.269 #> 4 2 b -1 0.731