spq_arrange | R Documentation |
Arrange results by variable value
spq_arrange(.query, ..., .replace = FALSE)
.query |
a list with elements of the query |
... |
variables by which to arrange
(or SPARQL strings escaped with |
.replace |
whether to replace the pre-existing arranging |
A query object
# descending length, ascending item_label, "R" syntax
spq_init() %>%
spq_add("?item wdt:P31/wdt:P279* wd:Q4022") %>%
spq_label(item) %>%
spq_add("?item wdt:P2043 ?length") %>%
spq_add("?item wdt:P625 ?location") %>%
spq_arrange(desc(length), item_label) %>%
spq_head(50)
# descending length, ascending item_label,
# "R" syntax with quotes e.g. for a loop
variable = "length"
spq_init() %>%
spq_add("?item wdt:P31/wdt:P279* wd:Q4022") %>%
spq_label(item) %>%
spq_add("?item wdt:P2043 ?length") %>%
spq_add("?item wdt:P625 ?location") %>%
spq_arrange(sprintf("desc(%s)", variable), item_label) %>%
spq_head(50)
# descending length, ascending item_label, SPARQL syntax
spq_init() %>%
spq_add("?item wdt:P31/wdt:P279* wd:Q4022") %>%
spq_label(item) %>%
spq_add("?item wdt:P2043 ?length") %>%
spq_add("?item wdt:P625 ?location") %>%
spq_arrange(spq("DESC(?length) ?item_label")) %>%
spq_head(50)
# descending xsd:integer(mort), R syntax
spq_init() %>%
spq_add("?oeuvre dcterms:creator ?auteur") %>%
spq_add("?auteur bio:death ?mort") %>%
spq_add("?auteur foaf:familyName ?nom") %>%
spq_filter(as.integer(mort) < as.integer("1924")) %>%
spq_group_by(auteur, nom, mort) %>%
spq_arrange(desc(as.integer(mort)))
# descending as.integer(mort), SPARQL syntax
spq_init() %>%
spq_add("?oeuvre dcterms:creator ?auteur") %>%
spq_add("?auteur bio:death ?mort") %>%
spq_add("?auteur foaf:familyName ?nom") %>%
spq_filter(as.integer(mort) < as.integer("1924")) %>%
spq_group_by(auteur, nom, mort) %>%
spq_arrange(spq("DESC(xsd:integer(?mort))"))
# Usage of the .replace argument
# .replace = FALSE (default)
spq_init() %>%
spq_add("?item wdt:P31/wdt:P279* wd:Q4022") %>%
spq_label(item) %>%
spq_add("?item wdt:P2043 ?length") %>%
spq_add("?item wdt:P625 ?location") %>%
spq_arrange(desc(length)) %>%
spq_arrange(location) %>%
spq_head(50)
# .replace = TRUE
spq_init() %>%
spq_add("?item wdt:P31/wdt:P279* wd:Q4022") %>%
spq_label(item) %>%
spq_add("?item wdt:P2043 ?length") %>%
spq_add("?item wdt:P625 ?location") %>%
spq_arrange(desc(length)) %>%
spq_arrange(location, .replace = TRUE) %>%
spq_head(50)
# Mixing syntaxes
spq_init() %>%
spq_add("?item wdt:P31/wdt:P279* wd:Q4022") %>%
spq_label(item) %>%
spq_add("?item wdt:P2043 ?length") %>%
spq_add("?item wdt:P625 ?location") %>%
spq_arrange(desc(length), spq("?location")) %>%
spq_head(50)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.