@@ -346,9 +346,32 @@ search_pv <- function(query,
346346 return (first_res ) # else we iterate through pages below
347347 }
348348
349- unique_sort_keys <- rep(" asc" , length(pk ))
350- names(unique_sort_keys ) <- pk
351- arg_list $ sort <- unique_sort_keys
349+ if (is.null(fields ))
350+ {
351+ # request the default fields returned by the first call, otherwise adding the pk below
352+ # will just return that/thoses fields.
353+ fields <- names(first_res $ data [[1 ]])
354+ }
355+
356+ # add pk here instead - pk fields not added to first_res
357+ # We need pk to be in the result for all_pages to work with ease, hence adding
358+ # it below
359+ pk <- get_ok_pk(endpoint )
360+
361+ fields <- unique(c(pk , fields ))
362+ abbreviated_fields <- sub_grp_names_for_fields(endpoint , fields )
363+ arg_list $ fields <- abbreviated_fields
364+
365+ required_paging_keys <- rep(" asc" , length(pk ))
366+ names(required_paging_keys ) <- pk
367+
368+ # append required_paging_keys to user's sort if needed when supplied
369+ if (is.null(sort )) {
370+ arg_list $ sort <- required_paging_keys
371+ } else {
372+ non_duplicate_keys <- setdiff(names(required_paging_keys ), names(sort ))
373+ arg_list $ sort <- c(sort , required_paging_keys [non_duplicate_keys ])
374+ }
352375
353376 paged_data <- request_apply(
354377 first_res , method , query , base_url , arg_list , api_key , ...
0 commit comments