These functions are inspired by dplyr::count() and dplyr::tally().
spq_tally() assumes you've already done the grouping.
Arguments
- .query
- a list with elements of the query 
- sort
- If - TRUE, will show the largest groups at the top. (like the- sortargument of- dplyr::tally())
- name
- Name for the count column (like the - nameargument of- dplyr::tally())
- ...
- variables by which to arrange (or SPARQL strings escaped with - spq(), or strings, see examples)
Examples
# \dontrun{
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(narrative_location) %>%
spq_tally(name = "n_films") %>%
spq_perform()
#> # A tibble: 1 × 1
#>   n_films
#>     <int>
#> 1   51290
# the same with spq_count
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(narrative_location) %>%
spq_count(name = "n_films") %>%
spq_perform()
#> # A tibble: 1 × 1
#>   n_films
#>     <int>
#> 1   51290
# Now with grouping
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(film, narrative_location) %>%
spq_group_by(narrative_location_label) %>%
spq_tally(sort = TRUE, name = "n_films") %>%
spq_perform()
#> # A tibble: 2,796 × 2
#>    narrative_location_label n_films
#>    <chr>                      <int>
#>  1 Indonesia                   3089
#>  2 New York City               2547
#>  3 London                      2223
#>  4 Paris                       1854
#>  5 Los Angeles                 1495
#>  6 England                     1427
#>  7 Rome                         969
#>  8 California                   839
#>  9 France                       795
#> 10 Hong Kong                    706
#> # ℹ 2,786 more rows
# More direct with spq_count()
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(film, narrative_location) %>%
spq_count(narrative_location_label, sort = TRUE, name = "n_films") %>%
spq_perform()
#> # A tibble: 2,796 × 2
#>    narrative_location_label n_films
#>    <chr>                      <int>
#>  1 Indonesia                   3089
#>  2 New York City               2547
#>  3 London                      2223
#>  4 Paris                       1854
#>  5 Los Angeles                 1495
#>  6 England                     1427
#>  7 Rome                         969
#>  8 California                   839
#>  9 France                       795
#> 10 Hong Kong                    706
#> # ℹ 2,786 more rows
# }
