default_n {rando} | R Documentation |
Find the Default Value for n in Context
Description
Checks for various information surrounding the call to this function to figure out what value for n should be used
Usage
default_n(...)
blueprint_n()
tibble_n()
dplyr_n()
args_n(...)
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:
-
blueprint_n()
- Checks if the function is being called within a blueprinting function, and returns the value supplied to that function, seeblueprint()
. -
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 yourtibble()
call, seetibble()
-
dplyr_n()
- Checks if the function is being used within adplyr
verb, if so, it returns the value ofn()
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
# 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)