Skip to content

Commit

Permalink
Increase internal limit of atlas_counts() #198
Browse files Browse the repository at this point in the history
* Limit increased from 30 to 10,000
* Add message when limit is hit
  • Loading branch information
daxkellie committed Dec 22, 2023
1 parent 2b112c7 commit 12d441f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 6 additions & 1 deletion R/collapse_occurrences_count.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ collapse_occurrences_count_atlas <- function(identify = NULL,
facets <- as.list(group_by$name)
names(facets) <- rep("facets", length(facets))
if(is.null(slice)){
slice <- tibble(slice_n = 30, slice_called = FALSE)
# limits to 10,000 rows
# TODO: This should ultimately be set by `slice` or `atlas_counts(limit = )`, not internally.
# Will need updating to avoid hidden limit setting here & in `compute_occurrences_count()`
slice <- tibble(slice_n = 1e4, slice_called = FALSE)
}
if(is.null(arrange)){
arrange <- tibble(variable = "count", direction = "descending")
}

slice_arrange <- bind_cols(slice, arrange)
arrange_list <- check_slice_arrange(slice_arrange)
url$query <- c(query, facets, arrange_list)
result$url <- url_build(url)
result$expand <- ifelse(length(facets) > 1, TRUE, FALSE)
result$arrange <- slice_arrange
}

# aggregate and return
result$headers <- build_headers()
class(result) <- "query"
Expand Down
23 changes: 21 additions & 2 deletions R/compute_occurrences_count.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,35 @@ compute_occurrences_count <- function(.query){
#' @keywords Internal
compute_occurrences_count_nogroupby <- function(.query){
url <- url_parse(.query$url)

# check if a limit has been set
if(!is.null(url$query$flimit)){

# check number of total facets in the field
n_facets <- check_facet_count(.query)

# handle slice_head
if(as.integer(url$query$flimit) < 1){
n_facets <- check_facet_count(.query)
url$query$flimit <- .query$arrange$slice_n # Q: is this correct?
if(.query$arrange$slice_n < n_facets){
url$query$foffset <- n_facets - .query$arrange$slice_n
}
.query$url <- url_build(url)
.query

# message when limit is hit
}else{
if(as.integer(url$query$flimit) < n_facets){
limit <- url$query$flimit |> prettyNum(big.mark=",", preserve.width="none")
n_total_facets <- n_facets |> prettyNum(big.mark=",", preserve.width="none")

bullets <- c(
cli::cli_text(cli::col_yellow(glue("Limiting to first {limit} of {n_total_facets} rows."))),
cli::cli_text(cli::col_magenta("Use `atlas_counts(limit = )` to return more rows."))
)
inform(bullets)
}
# .query$url <- url_build(url)
.query
}
}else{
Expand Down Expand Up @@ -91,7 +110,7 @@ compute_occurrences_count_groupby <- function(.query, error_call = caller_env())
saved_facet_queries <- saved_facet_queries[
unlist(lapply(saved_facet_queries, function(a){!is.null(a)}))]

# rebuild url
# rebuild url with only first facet argument
url$query <- c(
url$query[names(url$query) != "facets"],
facet_list[-length(facet_list)])
Expand Down

0 comments on commit 12d441f

Please sign in to comment.