getColPats2: Get named color patterns with names preset or from other...

Description Usage Arguments Value Examples

Description

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:

Usage

1
2
3
4
5
6
7
8
getColPats2(
  targets,
  colorsFrom = "color_",
  rename = TRUE,
  namesFrom = NULL,
  unique = FALSE,
  pullVar = NULL
)

Arguments

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

Value

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

Examples

 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)

peterjuv/FunGenPipe documentation built on June 18, 2021, 3:38 a.m.