From 1dfca62e4ccf4a041b7d57abe115e4c0fea24160 Mon Sep 17 00:00:00 2001 From: Ahmad Jan Date: Mon, 6 May 2024 10:00:09 -0400 Subject: [PATCH] fixed a corner case, when size of the 'first break' is smaller than the user-provided size of the 'first break'. --- R/custom_function.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/custom_function.R b/R/custom_function.R index 3f98a77..de83de1 100644 --- a/R/custom_function.R +++ b/R/custom_function.R @@ -41,11 +41,23 @@ circular_mean <- function (value, coverage_fraction) { distribution = function(value, coverage_fraction, breaks = 10, constrain = FALSE){ + if (length(value) <= 0 | all(is.nan(value))) { + return("[]") + } + x1 = value*coverage_fraction x1 = x1[!is.na(x1)] if(constrain | length(breaks) > 1){ + + breaks_tmp = c(breaks[1],breaks[2]) + breaks = breaks[!breaks > max(x1, na.rm = TRUE)] + + if (length(breaks) == 1){ + breaks = breaks_tmp + } + } tmp = as.data.frame(table(cut(x1, breaks = breaks)))