Closed sckott closed 8 years ago
dplyr would be the other place to look, as many of the verbs are going to be the same. Unfortunately I don't really use the package so can't really comment. lazyeval seems like the right call, probably using https://github.com/hadley/lazyeval
@richfitz started hacking on dsl a bit, e.g.,
library("httr")
library("jsonlite")
out <- minify(content(GET('https://api.github.com/repos/stedolan/jq/commits?per_page=5'), "text"))
# the jq call, and equivalent with dsl
# jq '.'
out %>% dot() %>% jq
# jq '.[]'
out %>% index() %>% jq
# jq '.[0]'
out %>% index(0) %>% jq
# jq '.[1]'
out %>% index(1) %>% jq
# jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
out %>% index(0) %>% select(message = .commit.message, name = .commit.committer.name) %>% jq
# jq '.[] | {message: .commit.message, name: .commit.committer.name}'
out %>% index() %>% select(message = .commit.message, name = .commit.committer.name) %>% jq
Are there ways of testing if the operator is the last in a chain? Then we could omit the jq() call e.g.? But this whole chaining thing is pretty new to me :smiley:
good question @richfitz - i have asked Stefan before, - maybe that SO thread has an answer - I'll try that, would be nice to get rid of jq()
call at the end.
With rex
, it seems that they don't pipe operations together, but instead compose one big query specification. Do you think that's a better approach? I think probably not, but that would be easier to develop i guess
this is fully implemented now, i'll open a separate issue asking for feedback on the DSL
As @richfitz mentioned, rex provides a good example of how we could build a dsl to define jq queries. @richfitz you like the lazyeval approach? want to use here?