if_col_present {interfacer} | R Documentation |
Execute a function or return a value if a column in present in a dataframe
Description
The simple use case. For more complex behaviour see switch_pipeline()
.
Usage
if_col_present(df, col, if_present, if_missing = ~.x)
Arguments
df |
a dataframe |
col |
a column name |
if_present |
a |
if_missing |
a |
Value
either the value of if_present
/if_absent
or the result of calling
if_present
/if_absent
as functions on df
.
Examples
iris %>% if_col_present(Species, ~ .x %>% dplyr::rename(new = Species)) %>%
colnames()
# in contrast to `purrr` absolute values are not interpreted as function names
iris %>% if_col_present(Species2, "Yes", "No")
[Package interfacer version 0.3.3 Index]