lvaudor / glitter

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

Use of "?s ?v {object}" in functions #170

Open lvaudor opened 1 year ago

lvaudor commented 1 year ago

Hey!

I'm working on a vignette in which I want to run a "combined" query. First I go and search laboratory identifiers (lab) and then I try and find all publishing people affiliated to this lab.

For example, lab_EVS="https://data.archives-ouvertes.fr/structure/390864"

This does not work if I remove the call to glue::glue(), I guess because of something to do with environments :

get_docs_lab=function(lab){
  lab=paste0("<",lab,">")
  result=spq_init() %>%      
  spq_add(glue::glue("?createur hal:structure {lab}")) %>% 
  spq_add("?createur hal:person ?personne") %>%        
  spq_add("?personne foaf:name ?auteur") %>% 
  spq_group_by(auteur) %>% 
  spq_summarise() %>% 
  spq_perform("hal")    
  return(result)
}
get_docs_lab(lab_EVS)

I find that (mildly) annoying because the use of this {object} notation in triple patterns is mainly useful when used in combined queries and thus in functions (well, for those who use purrr instead of [for] loops anyway).

Actually the only other use that I can think of the {object} notation (when not used for iterative processes) is keeping the query "nice and concise" i.e. instead of showing long urls in the code, one can assign a name to these urls and use the name in the query.

(Anyway, the necessity to use glue::glue is NOT a big problem but it's still something more to think of when building combined queries so I just thought I should document this somewhere ;-) )

maelle commented 1 year ago

Ah nice, let me look how {cli} handles this, I know it has glue-like syntax. Or we could use glue under the hood anyway :thinking:

maelle commented 1 year ago

mmh so it's not as easy as I thought.

I wonder whether it's worth the complexity, honestly, compared to letting the users construct their strings.