default_n: Find the Default Value for n in Context

Description Usage Arguments Details Value Examples

View source: R/default_n.R

Description

Checks for various information surrounding the call to this function to figure out what value for n should be used

Usage

1
2
3
4
5
6
7
8
9

Arguments

...

parameters to check the lengths of

Details

The default_n() function will run through the other functions found here until it finds a viable value for n.

It first checks for contxt to see if calls external to default_n() indicate which value should be used:

It then checks the lengths of the arguments supplied via ..., if there is a discrepancy between these arguments and the context aware value found above, it will throw an error.

If all the above values return 1 or NULL, we then check for a global n assigned by set_n(), if none is set then default_n() will return 1.

Value

The context aware value for n

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Global Values:
set_n(NULL)
default_n()
set_n(10)
default_n()

# In a blueprint:
bp <- blueprint(x=r_norm(),n=default_n())
bp(n=7)
bp <- blueprint(x=r_norm(),n=blueprint_n())
bp(n=8)

# In a tibble:
tibble::tibble(id = 1:3, n = default_n())
tibble::tibble(id = 1:5, n = tibble_n())

# In a dplyr verb:
df <- tibble::tibble(id = 1:4)
dplyr::mutate(df, n = default_n())
dplyr::mutate(df, n = dplyr_n())

# From arguments:
default_n(1:5)
default_n(1:5,c("a","b","c","d","e"))
args_n(1:3,c("a","b","d"))
args_n(1:3, 1:4)

## Not run: 
default_n(1:3, 1:4)
tibble::tibble(id=1:5,n=default_n(1:4))

## End(Not run)

rando documentation built on Feb. 16, 2021, 5:07 p.m.