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(...)
... | parameters to check the lengths of |
---|
The context aware value for n
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
.
#> [1] 1#> [1] 10#> # 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#> # 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#> # A tibble: 3 x 2 #> id n #> <int> <dbl> #> 1 1 3 #> 2 2 3 #> 3 3 3#> # A tibble: 5 x 2 #> id n #> <int> <int> #> 1 1 5 #> 2 2 5 #> 3 3 5 #> 4 4 5 #> 5 5 5#> # A tibble: 4 x 2 #> id n #> <int> <dbl> #> 1 1 4 #> 2 2 4 #> 3 3 4 #> 4 4 4#> # 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#> [1] 5#> [1] 3 3args_n(1:3, 1:4)#> [1] 3 4