Skip to content

Commit

Permalink
Removing unused code.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicChr committed Oct 7, 2024
1 parent 5deae35 commit 8e9b943
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 278 deletions.
277 changes: 0 additions & 277 deletions R/get_breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,280 +188,3 @@ pretty_ceiling <- function(x, base = 10){
scale <- log_scale(x, base)
nearest_ceiling(x, (base ^ scale))
}
# Like the above with special handling of small values
# pretty_floor2 <- function(x){
# scale <- log_scale(x, 10)
# nearest_factor <- 10 ^ scale
# ax <- abs(x)
# manual <- which_(
# (ax < 1) |
# (ax > 2 & ax < 5) |
# (ax > 5 & ax < 10)
# )
# nearest_factor[manual] <- (10 ^ (scale[manual] + 1)) / 2
# nearest_floor(x, nearest_factor)
# }
# pretty_ceiling2 <- function(x){
# scale <- log_scale(x, 10)
# nearest_factor <- 10 ^ scale
# ax <- abs(x)
# manual <- which_(
# (ax < 1) |
# (ax > 2 & ax < 5) |
# (ax > 5 & ax < 10)
# )
# nearest_factor[manual] <- (10 ^ (scale[manual] + 1)) / 2
# nearest_ceiling(x, nearest_factor)
# }

### Alternative
# get_breaks2 <- function(x, n = 7,
# pretty = TRUE,
# expand_min = FALSE,
# expand_max = FALSE,
# ...){
# check_length(n, 1L)
# stopifnot(n >= 1)
#
# rng <- as.double(collapse::frange(x, na.rm = TRUE, finite = TRUE))
# if (any_na(rng) || all(is.infinite(rng))){
# return(NA_real_)
# }
# rng_width <- diff(rng)
# start <- rng[1]
# end <- rng[2]
# spans_zero <- abs(diff(sign(rng))) == 2
#
# if (isTRUE(rng_width == 0)){
# return(seq(start - 0.05, end + 0.05, by = 0.1 / max((n - 1), 1)))
# }
#
# if (!pretty){
#
# # The way cut() does it
# width <- rng_width / n
# out <- seq(start, end, by = width)
# if (expand_min){
# out[1] <- start - (rng_width * 0.001)
# }
# if (expand_max){
# out[length(out)] <- end + (rng_width * 0.001)
# }
# out
#
# } else {
#
# # Make end-points prettier
#
# scale_diff <- log_scale(rng_width) - log_scale(start)
#
# # If large range & relatively small starting value
# # floor start to the nearest difference in orders of magnitude
#
# # If range spans across zero and start val is small
# if (scale_diff >= 1 && spans_zero && abs(start) < 1){
# adj_start <- nearest_floor(start, 10^(log_scale(end)))
# } else {
# adj_start <- nearest_floor(start, 10^(scale_diff))
# }
#
# adj_rng_width <- end - adj_start
#
# # Calculate bin-width (guaranteed to span end-points inclusively)
# bin_width <- adj_rng_width / n
#
# # if (bin_width < 1){
# # # adj_width <- nearest_ceiling(bin_width, 10 ^ (floor(log10(bin_width))))
# # adj_width <- nearest_ceiling(bin_width, 10 ^ ( (floor(log10(bin_width)) + 1) / 2))
# # } else
# if (bin_width > 2 && bin_width < 5){
# adj_width <- 5
# } else if (bin_width > 5 && bin_width < 10){
# adj_width <- 10
# } else {
# adj_width <- pretty_ceiling(bin_width)
# }
# adj_width <- round(adj_width, 6)
#
# # Second adjustment to start value
# adj_start <- nearest_floor(adj_start, 10^log_scale(adj_width))
#
# # Reduce floating-point error
# # If width is almost a whole number, just round it
#
# last_break_is_short <- isTRUE(is_integerable(seq_to(n + 3, adj_start, by = adj_width)))
#
# # Also this produces an integer sequence
# if (isTRUE(abs(adj_width - round(adj_width)) < sqrt(.Machine$double.eps))){
# adj_width <- round(adj_width)
# if (last_break_is_short){
# adj_width <- as.integer(adj_width)
# }
# }
# if (isTRUE(abs(adj_start - round(adj_start)) < sqrt(.Machine$double.eps))){
# adj_start <- round(adj_start)
# if (last_break_is_short){
# adj_start <- as.integer(adj_start)
# }
# }
#
#
# # Breaks
#
# n_breaks <- n + 1
# if (expand_max){
# n_breaks <- n_breaks + 2 # 2 for good measure
# }
#
# if (expand_min && adj_start >= start){
# adj_start <- adj_start - adj_width
# }
#
# out <- seq(adj_start, by = adj_width, length.out = n_breaks)
#
# rm <- which_(out > end)
#
# if (expand_max && (length(rm) > 0)){
# rm <- rm[-1L]
# }
#
# # Remove outlier breaks
#
# if (length(rm) > 0){
# out <- out[-rm]
# }
#
# out
# }
# }

# get_breaks3 <- function(x, n = 7,
# pretty = TRUE,
# expand_min = FALSE,
# expand_max = FALSE,
# ...){
# check_length(n, 1L)
# stopifnot(n >= 1)
#
# rng <- as.double(collapse::frange(x, na.rm = TRUE, finite = TRUE))
# if (any_na(rng) || all(is.infinite(rng))){
# return(NA_real_)
# }
# rng_width <- diff(rng)
# start <- rng[1]
# end <- rng[2]
# spans_zero <- abs(diff(sign(rng))) == 2
#
# if (isTRUE(rng_width == 0)){
# return(seq(start - 0.05, end + 0.05, by = 0.1 / max((n - 1), 1)))
# }
#
# if (!pretty){
#
# # The way cut() does it
# width <- rng_width / n
# out <- seq(start, end, by = width)
# if (expand_min){
# out[1] <- start - (rng_width * 0.001)
# }
# if (expand_max){
# out[length(out)] <- end + (rng_width * 0.001)
# }
# out
#
# } else {
#
# # Make end-points prettier
#
# adj_start <- pretty_floor(start)
# scale_diff <- log_scale(rng_width) - log_scale(adj_start)
#
# # If large range & relatively small starting value
# # floor start to the nearest difference in orders of magnitude
#
# # If range spans across zero and start val is small
# if (scale_diff >= 1 && spans_zero && abs(adj_start) < 1){
# adj_start <- nearest_floor(adj_start, 10^(log_scale(end)))
# } else {
# adj_start <- nearest_floor(adj_start, 10^(scale_diff))
# }
#
# adj_rng_width <- end - adj_start
#
# # Calculate bin-width (guaranteed to span end-points inclusively)
# bin_width <- adj_rng_width / n
#
# # if (bin_width < 1){
# # # adj_width <- nearest_ceiling(bin_width, 10 ^ (floor(log10(bin_width))))
# # adj_width <- nearest_ceiling(bin_width, 10 ^ ( (floor(log10(bin_width)) + 1) / 2))
# # } else
# if (bin_width > 2 && bin_width < 5){
# adj_width <- 5
# } else if (bin_width > 5 && bin_width < 10){
# adj_width <- 10
# } else {
# adj_width <- pretty_ceiling(bin_width)
# }
# adj_width <- round(adj_width, 6)
#
# # Second adjustment to start value
# adj_start <- nearest_floor(adj_start, 10^log_scale(adj_width))
#
# # Reduce floating-point error
# # If width is almost a whole number, just round it
#
# last_break_is_short <- isTRUE(is_integerable(seq_to(n + 3, adj_start, by = adj_width)))
#
# # Also this produces an integer sequence
# if (isTRUE(abs(adj_width - round(adj_width)) < sqrt(.Machine$double.eps))){
# adj_width <- round(adj_width)
# if (last_break_is_short){
# adj_width <- as.integer(adj_width)
# }
# }
# if (isTRUE(abs(adj_start - round(adj_start)) < sqrt(.Machine$double.eps))){
# adj_start <- round(adj_start)
# if (last_break_is_short){
# adj_start <- as.integer(adj_start)
# }
# }
#
#
# # Breaks
#
# n_breaks <- n + 1
# if (expand_max){
# n_breaks <- n_breaks + 2 # 2 for good measure
# }
#
# if (expand_min && adj_start >= start){
# adj_start <- adj_start - adj_width
# }
#
# out <- seq(adj_start, by = adj_width, length.out = n_breaks)
#
# ## Remove outliers
#
# rm <- which_(out > end)
#
# if (expand_max && (length(rm) > 0)){
# rm <- rm[-1L]
# }
#
# if (length(rm) > 0){
# out <- out[-rm]
# }
#
# rm <- which_(out < start)
#
# if (expand_min && (length(rm) > 0)){
# rm <- rm[-1L]
# }
#
# if (length(rm) > 0){
# out <- out[-rm]
# }
#
# out
# }
# }
2 changes: 1 addition & 1 deletion man/as_discrete.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e9b943

Please sign in to comment.