@@ -347,19 +347,20 @@ search_pv <- function(query,
347
347
arg_list <- to_arglist(fields , size , primary_sort_key , after )
348
348
paged_data <- request_apply(result , method , query , base_url , arg_list , api_key , ... )
349
349
350
- # apply the user's sort using order()
350
+ # we apply the user's sort, if they supplied one, using order()
351
351
# was data.table::setorderv(paged_data, names(sort), ifelse(as.vector(sort) == "asc", 1, -1))
352
-
353
- sort_order <- mapply(function (col , direction ) {
354
- if (direction == " asc" ) {
355
- return (paged_data [[col ]])
356
- } else {
357
- return (- rank(paged_data [[col ]], ties.method = " min" )) # Invert for descending order
358
- }
359
- }, col = names(sort ), direction = as.vector(sort ), SIMPLIFY = FALSE )
360
-
361
- # Final sorting
362
- paged_data <- paged_data [do.call(order , sort_order ), , drop = FALSE ]
352
+ if (! is.null(sort )) {
353
+ sort_order <- mapply(function (col , direction ) {
354
+ if (direction == " asc" ) {
355
+ return (paged_data [[col ]])
356
+ } else {
357
+ return (- rank(paged_data [[col ]], ties.method = " min" )) # Invert for descending order
358
+ }
359
+ }, col = names(sort ), direction = as.vector(sort ), SIMPLIFY = FALSE )
360
+
361
+ # Final sorting
362
+ paged_data <- paged_data [do.call(order , sort_order ), , drop = FALSE ]
363
+ }
363
364
364
365
# remove the fields we added in order to do the user's sort ourselves
365
366
paged_data <- paged_data [, ! names(paged_data ) %in% additional_fields ]
0 commit comments