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

default_n(...)

blueprint_n()

tibble_n()

dplyr_n()

args_n(...)

Arguments

...

parameters to check the lengths of

Value

The context aware value for n

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:

  • blueprint_n() - Checks if the function is being called within a blueprinting function, and returns the value supplied to that function, see blueprint().

  • tibble_n() - Checks if the function is being called within the declaration of a tibble. It then checks the lengths of the other arguments being passed to the call. If you want to specify how many rows should be generate you can use the .rows argument in your tibble() call, see tibble()

  • dplyr_n() - Checks if the function is being used within a dplyr verb, if so, it returns the value of n()

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.

Examples

# Global Values: set_n(NULL) default_n()
#> [1] 1
set_n(10) default_n()
#> [1] 10
# In a blueprint: bp <- blueprint(x=r_norm(),n=default_n()) bp(n=7)
#> # A tibble: 7 x 2 #> x n #> <dbl> <dbl> #> 1 1.07 7 #> 2 0.0700 7 #> 3 -0.639 7 #> 4 -0.0500 7 #> 5 -0.251 7 #> 6 0.445 7 #> 7 2.76 7
bp <- blueprint(x=r_norm(),n=blueprint_n()) bp(n=8)
#> # A tibble: 8 x 2 #> x n #> <dbl> <dbl> #> 1 0.0465 8 #> 2 0.578 8 #> 3 0.118 8 #> 4 -1.91 8 #> 5 0.862 8 #> 6 -0.243 8 #> 7 -0.206 8 #> 8 0.0192 8
# In a tibble: tibble::tibble(id = 1:3, n = default_n())
#> # A tibble: 3 x 2 #> id n #> <int> <dbl> #> 1 1 3 #> 2 2 3 #> 3 3 3
tibble::tibble(id = 1:5, n = tibble_n())
#> # A tibble: 5 x 2 #> id n #> <int> <int> #> 1 1 5 #> 2 2 5 #> 3 3 5 #> 4 4 5 #> 5 5 5
# In a dplyr verb: df <- tibble::tibble(id = 1:4) dplyr::mutate(df, n = default_n())
#> # A tibble: 4 x 2 #> id n #> <int> <dbl> #> 1 1 4 #> 2 2 4 #> 3 3 4 #> 4 4 4
dplyr::mutate(df, n = dplyr_n())
#> # A tibble: 4 x 2 #> id n #> <int> <int> #> 1 1 4 #> 2 2 4 #> 3 3 4 #> 4 4 4
# From arguments: default_n(1:5)
#> [1] 5
default_n(1:5,c("a","b","c","d","e"))
#> [1] 5
args_n(1:3,c("a","b","d"))
#> [1] 3 3
args_n(1:3, 1:4)
#> [1] 3 4
if (FALSE) { default_n(1:3, 1:4) tibble::tibble(id=1:5,n=default_n(1:4)) }