lvaudor / glitter

an R package which writes SPARQL queries
https://lvaudor.github.io/glitter
44 stars 5 forks source link

Order of columns #167

Closed lvaudor closed 1 year ago

lvaudor commented 1 year ago

Hi! Right now queries return the tables with the xxx columns in alphabetical order, then all xxx_label columns in alphabetical order. Unfortunately I find that quite impractical. I'd rather have the order of columns corresponding to the order of the query + xxx_label right beside xxx.

For instance:

stations_metro_Lyon=spq_init() %>% 
  spq_add("?station wdt:P16 wd:Q1552") %>% 
  spq_add("?station wdt:P31 wd:Q928830") %>%
  spq_add("?station wdt:P625 ?coords") %>%
  spq_add("?station p:P197 ?statement") %>%          
  spq_add("?statement ps:P197 ?adjacent") %>%        
  spq_add("?statement pq:P81 ?line") %>%      
  spq_add("?statement pq:P5051 ?direction") %>%   
  spq_label("station", "adjacent", "line", "direction") %>% 
  spq_perform() 

would return a table with columns

maelle commented 1 year ago
library("glitter")
spq_init() %>% 
  spq_add("?station wdt:P16 wd:Q1552") %>% 
  spq_add("?station wdt:P31 wd:Q928830") %>%
  spq_add("?station wdt:P625 ?coords") %>%
  spq_add("?station p:P197 ?statement") %>%          
  spq_add("?statement ps:P197 ?adjacent") %>%        
  spq_add("?statement pq:P81 ?line") %>%      
  spq_add("?statement pq:P5051 ?direction") %>%   
  spq_label("station", "adjacent", "line", "direction") %>% 
  spq_perform()
#> # A tibble: 83 × 10
#>    adjacent     adjacent_label coords direction direction_label line  line_label
#>    <chr>        <chr>          <chr>  <chr>     <chr>           <chr> <chr>     
#>  1 http://www.… <NA>           Point… http://w… <NA>            http… Lyon Metr…
#>  2 http://www.… <NA>           Point… http://w… <NA>            http… Lyon Metr…
#>  3 http://www.… Hôtel de Vill… Point… http://w… Hôtel de Ville… http… Lyon Metr…
#>  4 http://www.… Croix-Paquet   Point… http://w… Hôtel de Ville… http… Lyon Metr…
#>  5 http://www.… Hénon          Point… http://w… Hôtel de Ville… http… Lyon Metr…
#>  6 http://www.… Croix-Rousse   Point… http://w… Hôtel de Ville… http… Lyon Metr…
#>  7 http://www.… Gare de Vénis… Point… http://w… Gare de Véniss… http… Lyon Metr…
#>  8 http://www.… Saxe - Gambet… Point… http://w… Gare de Véniss… http… Lyon Metr…
#>  9 http://www.… Gorge de Loup  Point… http://w… Gare de Véniss… http… Lyon Metr…
#> 10 http://www.… Guillotière -… Point… http://w… Gare de Véniss… http… Lyon Metr…
#> # ℹ 73 more rows
#> # ℹ 3 more variables: statement <chr>, station <chr>, station_label <chr>

Created on 2023-09-07 with reprex v2.0.2

lvaudor commented 1 year ago

indeed! it does just the alphabetical order, independently of "_label"

maelle commented 1 year ago

the PR to review is at #172