Skip to contents

Offset the first generated result

Usage

spq_offset(.query, n = 5)

Arguments

.query

a list with elements of the query

n

the maximum number of lines to return

Value

A query object

Subsetting

spq_offset() and spq_head() are only useful when used with spq_arrange() that makes the order of results predictable.

Examples

# Return 42 items
spq_init() %>%
spq_add("?item wdt:P31 wd:Q5") %>%
spq_label(item) %>%
spq_add("?item wdt:P19/wdt:P131* wd:Q60") %>%
spq_add("?item wikibase:sitelinks ?linkcount") %>%
spq_arrange(desc(linkcount)) %>%
spq_head(n=42)
#> PREFIX wd: <http://www.wikidata.org/entity/>
#> PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#> PREFIX wikibase: <http://wikiba.se/ontology#>
#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
#> SELECT ?item (COALESCE(?item_labell,'') AS ?item_label) ?linkcount
#> WHERE {
#> 
#> ?item wdt:P31 wd:Q5.
#> OPTIONAL {
#> ?item rdfs:label ?item_labell.
#> FILTER(lang(?item_labell) IN ('en'))
#> }
#> 
#> ?item wdt:P19/wdt:P131* wd:Q60.
#> ?item wikibase:sitelinks ?linkcount.
#> 
#> }
#> ORDER BY DESC(?linkcount)
#> LIMIT 42

# Return 42 items after the first 11 items
spq_init() %>%
spq_add("?item wdt:P31 wd:Q5") %>%
spq_label(item) %>%
spq_add("?item wdt:P19/wdt:P131* wd:Q60") %>%
spq_add("?item wikibase:sitelinks ?linkcount") %>%
spq_arrange(desc(linkcount)) %>%
spq_head(42) %>%
spq_offset(11)
#> PREFIX wd: <http://www.wikidata.org/entity/>
#> PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#> PREFIX wikibase: <http://wikiba.se/ontology#>
#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
#> SELECT ?item (COALESCE(?item_labell,'') AS ?item_label) ?linkcount
#> WHERE {
#> 
#> ?item wdt:P31 wd:Q5.
#> OPTIONAL {
#> ?item rdfs:label ?item_labell.
#> FILTER(lang(?item_labell) IN ('en'))
#> }
#> 
#> ?item wdt:P19/wdt:P131* wd:Q60.
#> ?item wikibase:sitelinks ?linkcount.
#> 
#> }
#> ORDER BY DESC(?linkcount)
#> LIMIT 42OFFSET 11