Skip to content

Commit

Permalink
Overview bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicChr committed Mar 23, 2024
1 parent e7c6474 commit 0dd070b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 2 additions & 10 deletions R/overview.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@ overview <- function(x, hist = FALSE, digits = getOption("cheapr.digits", 2)){
overview.default <- function(x, hist = FALSE, digits = getOption("cheapr.digits", 2)){
options(cheapr.digits = digits)
overview(list_as_df(list(x = x)), hist = hist)
# out <- overview(list_as_df(list(x = x)), hist = hist)$other
# out
}
#' @rdname overview
#' @export
overview.logical <- function(x, hist = FALSE, digits = getOption("cheapr.digits", 2)){
options(cheapr.digits = digits)
overview(list_as_df(list(x = as.logical(x))), hist = hist)
# out <- overview(list_as_df(list(x = as.logical(x))), hist = hist)$logical
# out
}
#' @rdname overview
#' @export
Expand All @@ -62,8 +58,6 @@ overview.numeric <- function(x, hist = FALSE, digits = getOption("cheapr.digits"
out <- overview(list_as_df(list(x = as.numeric(x))), hist = hist)
out$cols <- NA_integer_
out
# out <- overview(list_as_df(list(x = as.numeric(x))), hist = hist)$numeric
# out
}
#' @rdname overview
#' @export
Expand All @@ -72,8 +66,6 @@ overview.character <- function(x, hist = FALSE, digits = getOption("cheapr.digit
out <- overview(list_as_df(list(x = as.character(x))), hist = hist)
out$cols <- NA_integer_
out
# out <- overview(list_as_df(list(x = as.character(x))), hist = hist)$categorical
# out
}
#' @rdname overview
#' @export
Expand Down Expand Up @@ -254,7 +246,7 @@ overview.data.frame <- function(x, hist = FALSE, digits = getOption("cheapr.digi
if (N > 0L && length(which_ts) > 0) {
ts_overviews <- new_list(nrow(ts_out))
for (i in seq_along(ts_overviews)){
ts_overviews[[i]] <- overview(ts_data[[ts_out[["col"]][i]]], hist = hist)
ts_overviews[[i]] <- overview(ts_data[[ts_out[["col"]][i]]], hist = hist)$numeric
if (length(attr(ts_overviews[[i]], "row.names")) > 1){
ts_overviews[[i]][["col"]] <- paste0(ts_out[["col"]][i], "_",
ts_overviews[[i]][["col"]])
Expand Down Expand Up @@ -334,7 +326,7 @@ print.overview <- function(x, max = NULL, digits = getOption("cheapr.digits", 2)
# options(tibble.print_max = 10)
# options(tibble.width = 100)
# options(tibble.max_extra_cols = 10)
cat(paste("obs:", x$obs, "cols:", x$cols), "\n")
cat(paste("obs:", x$obs, "\ncols:", x$cols), "\n")
# for (data_type in names(x)[-(1:2)]){
# if (nrow(x[[data_type]])){
# cat(paste("\n-----", data_type, "-----\n"))
Expand Down
15 changes: 10 additions & 5 deletions tests/testthat/_snaps/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Code
overview(airquality, hist = FALSE)
Output
obs: 153 cols: 6
obs: 153
cols: 6
----- Numeric -----
col class n_missing p_complete n_unique mean p0 p25 p50 p75
Expand All @@ -26,7 +27,8 @@
Code
overview(iris, hist = FALSE)
Output
obs: 150 cols: 5
obs: 150
cols: 5
----- Numeric -----
col class n_missing p_complete n_unique mean p0 p25 p50 p75 p100
Expand All @@ -49,7 +51,8 @@
Code
overview(iris2, hist = FALSE)
Output
obs: 100 cols: 7
obs: 100
cols: 7
----- Logical -----
col class n_missing p_complete n_true n_false p_true
Expand Down Expand Up @@ -77,7 +80,8 @@
Code
overview(warpbreaks, hist = FALSE)
Output
obs: 54 cols: 3
obs: 54
cols: 3
----- Numeric -----
col class n_missing p_complete n_unique mean p0 p25 p50 p75 p100
Expand All @@ -95,7 +99,8 @@
Code
overview(ToothGrowth, hist = FALSE)
Output
obs: 60 cols: 3
obs: 60
cols: 3
----- Numeric -----
col class n_missing p_complete n_unique mean p0 p25 p50 p75 p100
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-overview.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test_that("overview", {
options(cheapr.digits = 2)
expect_snapshot(overview(airquality, hist = FALSE))
iris2 <- iris
iris2$large <- iris2$Sepal.Length >= 6
Expand All @@ -8,5 +9,7 @@ test_that("overview", {
expect_snapshot(overview(iris2, hist = FALSE))
expect_snapshot(overview(warpbreaks, hist = FALSE))
expect_snapshot(overview(ToothGrowth, hist = FALSE))
expect_identical(overview(ts(1:10))$numeric,
overview(data.frame(x = ts(1:10)))$time_series)
# expect_snapshot(overview(EuStockMarkets, hist = TRUE))
})

0 comments on commit 0dd070b

Please sign in to comment.