Data Science Desktop Survival Guide
by Graham Williams |
|||||
Pipeline Identity Operator |
{.}
. In R terms this is a compound statement
containing just the period whereby the period represents the
data. Effectively this is an operator that passes the data through
without processing it—an identity operator.
Why is this useful? Whilst we are building our pipeline, one line at a
time, we will be wanting to put a pipe at the end of each line, but of
cause we can not do so if there is no following operator. Also, whilst
debugging a pipeline, we may want to execute only a part of it, and so
the identity operator is handy there too.
As a typical scenario we might be in the process of building a
pipeline as here and find that including the tidyr::https://www.rdocumentation.org/packages/tidyr/topics/the end of the line of the dplyr::select() operation:
ds %>%
select(rainfall, min_temp, max_temp, sunshine) %>% {.}
We then add the next operation into the pipeline without having to modify any of the code already present: |
ds %>%
select(rainfall, min_temp, max_temp, sunshine) %>% summary() %>% {.}
And so on. Whilst it appears quite a minor convenience, over time as we build more pipelines, this becomes quite a handy trick. |