tests/testthat/test-gen_color_bars.R

context("gen color bars")

test_that("output object class and structure", {
  suppressWarnings(RNGversion("3.5.0"))
  set.seed(42)
  plot_df = data.frame(lab = letters,
                       val = rexp(26),
                       stringsAsFactors = FALSE)

  plot_df$max_rel_val = plot_df$val / sum(plot_df$val)

  output = gen_color_bars(plot_df, number_rows = 3, bar_color = "blue",
                          label_column = "lab", min_label_width = .03, "black")

  expect_identical(class(output), "list")

  expect_identical(class(output$raw_data), "data.frame")
  expect_identical(dim(output$raw_data), c(3L, 3L))

  expect_identical(class(output$bar_list), "list")
  expect_identical(length(output$bar_list), 3L)
  expect_identical(lapply(output$bar_list, length), list(9L, 9L, 9L))
  expect_identical(names(output$bar_list[[1]]),
                   c("type", "fillcolor", "line",
                     "x0", "x1", "xref", "y0", "y1", "yref"))
  expect_identical(lapply(output$bar_list[[1]], class),
                   list(type = "character", fillcolor = "character", line = "list",
                        x0 = "numeric", x1 = "numeric", xref = "character", y0 = "numeric",
                        y1 = "numeric", yref = "character"))

  expect_identical(class(output$ann_list), "list")
  expect_identical(length(output$ann_list), 3L)
  expect_identical(lapply(output$ann_list, length), list(8L, 8L, 8L))
  expect_identical(names(output$ann_list[[1]]),
                   c("x", "y", "xref", "yref", "text", "showarrow", "xanchor", "font"))
  expect_identical(lapply(output$ann_list[[1]], class),
                   list(x = "numeric", y = "numeric", xref = "character",
                        yref = "character", text = "character", showarrow = "logical",
                        xanchor = "character", font = "list"))

  expect_identical(class(output$hover_point_dt), c("data.table", "data.frame"))
  expect_identical(dim(output$hover_point_dt), c(75L, 4L))
  expect_identical(names(output$hover_point_dt), c("name", "x", "y", "size"))
  expect_identical(lapply(output$hover_point_dt, class), list(name = "character", x = "numeric",
                                                              y = "numeric", size = "numeric"))
})

Try the rPackedBar package in your browser

Any scripts or data that you put into this service are public.

rPackedBar documentation built on June 17, 2019, 9:02 a.m.