camr_assert | R Documentation |
camr_assert(any_x, lgl_expr, chr_message)
any_x |
An object, preferably a dataframe, to pass through. |
lgl_expr |
A logical expression to evaluate within any_x. |
chr_message |
A message to be displayed by stop() if lgl_expr is false. |
The purpose of this function is to enable pipeable assertions on dataframe columns without the need to break the pipe-chain or to use inline functions.
For example...
df_data |> (function (df) {if (!all(str_detect(df$x, '^a'))) stop('Elements of col x must start with "a".'); df})() |> ...
Can be written more readably...
df_data |> camr_assert(all(str_detect(x, '^a')), 'Elements of col x must start with "a".') |> ...
If the assertion passes, the object being tested will be passed through unchanged.
any_x
iris |>
camr_assert(
any(Species =='versicolor'),
'Dataset contains no irises of species versicolor'
) |>
summarize(
m_length = mean(Petal.Length)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.