Description Usage Arguments Value Examples
Returns columns from targets that start with "color_" and have their suffix in common with another column; column names are dropped prefix defined by parameter colorsFrom, e.g., "color_" New implementation allowing for alternative naming using parameter namesFrom. Names of colors may be:
preset (if rename = FALSE) or
set from the associated column, e.g., from Var for color_Var
set from a common coulmn for all colors set by namesFrom parameter, e.g., namesFrom=HybName If names contain NAs, names are convert to character type and NAs are replaced with "\<NA\>" Minimum 2 columns are required, e.g. Var and color_Var
1 2 3 4 5 6 7 8 |
targets |
Table with columns names with a prefix colorsFrom='color_' |
colorsFrom |
Character, non-empty prefix of names of columns with colors, default 'color_' |
rename |
Logical, default TRUE: rename colors using associated variables or variable namesFrom (default) FALSE: use existing names from 'color_' variables, or, if missing, use values from associated variables |
namesFrom |
Either NULL for using variables that share suffixes with colors or a variable from targets that is used for setting names to colors, e.g. HybName |
unique |
If TRUE, returns unique names and associated colors; Note that colors may be dropped, see the last example |
pullVar |
A variable from targets, e.g. Sex |
Named list of named colors for each variable from targets with an associated color. Names of variables correspond to color variables w/o colorsFrom prefix, e.g. "VarName" for "color_VarName" Names of colors correspond to values of an associated variable by default; alternatively, names are set to values form namesFrom variable. The lenght of each list is equal to the number of rows; alternatively, lists are truncated to unique names if unique=TRUE. If pullVar given, returns a single list of colors for that variable from targets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ## Not run:
(targets <- tibble::tibble(color_aa=c(1,1,2), color_bb=c("3"=3,"4"=4,"4"=4),
aa=c(11,11,22), bb=c(33,33,44), cc=c(55,66,55)))
names(targets$color_aa)
names(targets$color_bb)
getColPats2(targets)
# using namesFrom
getColPats2(targets, namesFrom=NULL)
getColPats2(targets, namesFrom=cc)
cc <- NULL
getColPats2(targets, namesFrom=cc)
d <- NULL
getColPats2(targets, namesFrom=d)
# using unique
getColPats2(targets, unique=TRUE)
getColPats2(targets, namesFrom=cc, unique=TRUE)
# using preset names, and if missing, substiting from associated variables
getColPats2(targets, rename=FALSE, namesFrom=NULL)
# names contain NA
targets[2,"aa"]<-NA; getColPats2(targets, rename=TRUE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.