-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path40-higher-order.Rmd
37 lines (25 loc) · 2.03 KB
/
40-higher-order.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# (PART) Advanced {-}
# Higher order widgets {#higher-order-widgets}
You may have noticed when we ran the `show_widgets()` function in [working with widgets](#working-with-finding-widgets) that there is a mysterious "Order" column that categorizes widgets as either "first-order" or "second-order". What's that all about? In order to answer that, let's take a look at another example.
## Children of wealth
Many alumni in our database do not have capacity ratings, but come from wealthy families. This would be nice to be aware of if they were ever being solicited. But how could we identify these "children of wealth" using the discovery engine? It's pretty easy to find wealthy individuals:
```{r higher-order-cow1}
# as always, i make sure the disco engine is loaded
library(discoveryengine)
# i'll define wealthy as a capacity of $1 Million+
wealthy = has_capacity(1:7)
```
But now I'm stuck. I want to find children of anyone on that list. But so far all of the widgets we've seen work with specific codes, not other widgets. Technically, all the widgets we've seen are *first-order* widgets. But we do have some widgets that, instead of working on one or more specific codes, works on an existing, already filled out widget. `child_of` is one such *second-order* widget:
```{r higher-order-cow2, cache = TRUE}
child_of_wealth = child_of(wealthy)
display(child_of_wealth)
```
Though the syntax looks just like what we've been doing all along, note that `wealthy` in the above is not a code or synonym, but instead is the name that I gave to the definition `has_capacity(1:7)`. This makes `child_of` very different from other widgets we've seen so far. As we'll see in the next seciton, the ability to use second-order widgets allows us to do some very powerful things.
The result of using a second-order widget, though, is just like using any other widget. You can continue to combine it with other widgets:
```{r higher-order-cow3, cache = TRUE}
display(child_of_wealth %and% lives_in_msa(san_francisco))
# or even
display(
child_of(child_of_wealth)
)
```