set_namer: set_namer / get_namer

Description Usage Arguments Details Value See Also Examples

View source: R/set_namer.R

Description

sets or gets the namer attribute of a function

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
set_namer(fun, namer, ...)

## Default S3 method:
set_namer(fun, namer, ...)

## S3 method for class ''function''
set_namer(fun, namer = NULL, ...)

## S3 method for class 'fseq'
set_namer(fun, namer = NULL, ...)

get_namer(fun)

Arguments

fun

function or fseq to convert to a naming function

namer

function or string; See Details.

Details

set_namer is a function decorator that adds/updates a namer`` attribute of fun'. It is also a mixin/role for adding additional capabilities to a function.

The namer argument can either be a string or function. If a function, this is used as the naming function. string, the naming function is to use this function as a suffix '

get_namer retrieves the naming function.

Value

fun with appended class 'with_namer' and the namer attribute set.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# With functions:

 f1 <- mean %>% set_namer( function(x) str_suffix(x,'.mean') )
 "price" %>% name_it(f1)       # "price.mean"

 f2 <- mean %>% set_namer( . %>% str_suffix('.mean') )
 "price" %>% name_it(f2)       # "price.mean"

 f3 <- mean %>% set_namer('.mean')
 "price" %>% name_it(f3)       # "price.mean"

 f4 <- mean %>% set_namer()
 "price" %>% name_it(f4)       # "price.mean"

 f5 <- set_namer(mean)
 "price" %>% name_it(f5)       # "price.mean"

# With fseq:
 f <- . %>% mean( na.rm=TRUE )
 f <- set_namer(f)
 "price" %>% name_it(f)        # "price.mean"

decisionpatterns/nameit documentation built on Aug. 22, 2020, 4:18 a.m.