select: Select - filtering

Description Usage Arguments Note Examples

View source: R/select.R

Description

The function select(foo) produces its input unchanged if foo returns TRUE for that input, and produces no output otherwise

Usage

1
2
3

Arguments

.data

input. This can be JSON input, or an object of class jqr that has JSON and query params combined, which is passed from function to function when using the jqr DSL.

...

Comma separated list of unquoted variable names

.dots

Used to work around non-standard evaluation

dots

dots

Note

this function has changed what it does dramatically. we were using this function for object construction, which is now done with build_object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
jq('[1,5,3,0,7]', 'map(select(. >= 2))')
'[1,5,3,0,7]' %>% map(select(. >= 2)) 


'{"foo": 4, "bar": 7}' %>% select(.foo == 4)
'{"foo": 5, "bar": 7} {"foo": 4, "bar": 7}' %>% select(.foo == 4)
'[{"foo": 5, "bar": 7}, {"foo": 4, "bar": 7}]' %>% index() %>% 
  select(.foo == 4)
'{"foo": 4, "bar": 7} {"foo": 5, "bar": 7} {"foo": 8, "bar": 7}' %>% 
  select(.foo < 6)

x <- '{"foo": 4, "bar": 2} {"foo": 5, "bar": 4} {"foo": 8, "bar": 12}'
jq(x, 'select((.foo < 6) and (.bar > 3))')
jq(x, 'select((.foo < 6) or (.bar > 3))')
x %>% select((.foo < 6) && (.bar > 3))
x %>% select((.foo < 6) || (.bar > 3))

x <- '[{"foo": 5, "bar": 7}, {"foo": 4, "bar": 7}, {"foo": 4, "bar": 9}]'
jq(x, '.[] | select(.foo == 4) | {user: .bar}')
x %>% index() %>% select(.foo == 4) %>% build_object(user = .bar)

ropensci/jqr documentation built on Oct. 26, 2018, 7:15 p.m.