EVOLUTION-MANAGER
Edit File: when.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Match/validate a set of conditions for an object and continue...</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for when {purrr}"><tr><td>when {purrr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Match/validate a set of conditions for an object and continue with the action associated with the first valid match.</h2> <h3>Description</h3> <p><code>when</code> is a flavour of pattern matching (or an if-else abstraction) in which a value is matched against a sequence of condition-action sets. When a valid match/condition is found the action is executed and the result of the action is returned. </p> <h3>Usage</h3> <pre> when(., ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.</code></td> <td> <p>the value to match against</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>formulas; each containing a condition as LHS and an action as RHS. named arguments will define additional values.</p> </td></tr> </table> <h3>Value</h3> <p>The value resulting from the action of the first valid match/condition is returned. If no matches are found, and no default is given, NULL will be returned. </p> <p>Validity of the conditions are tested with <code>isTRUE</code>, or equivalently with <code>identical(condition, TRUE)</code>. In other words conditions resulting in more than one logical will never be valid. Note that the input value is always treated as a single object, as opposed to the <code>ifelse</code> function. </p> <h3>Examples</h3> <pre> 1:10 %>% when( sum(.) <= 50 ~ sum(.), sum(.) <= 100 ~ sum(.)/2, ~ 0 ) 1:10 %>% when( sum(.) <= x ~ sum(.), sum(.) <= 2*x ~ sum(.)/2, ~ 0, x = 60 ) iris %>% subset(Sepal.Length > 10) %>% when( nrow(.) > 0 ~ ., ~ iris %>% head(10) ) iris %>% head %>% when(nrow(.) < 10 ~ ., ~ stop("Expected fewer than 10 rows.")) </pre> <hr /><div style="text-align: center;">[Package <em>purrr</em> version 0.3.4 <a href="00Index.html">Index</a>]</div> </body></html>