From 250ec559cd3e608da0470f284ec95dcddfd4a7fd Mon Sep 17 00:00:00 2001 From: Sandro Raabe Date: Sat, 28 Oct 2023 15:32:03 +0200 Subject: [PATCH] replace assertive package with assertthat --- DESCRIPTION | 10 +++---- NAMESPACE | 9 +++--- NEWS.md | 4 +++ R/plot_ggplot.R | 2 +- R/validate_input.R | 43 ++++++++++++++++------------ inst/WORDLIST | 1 + tests/testthat.R | 1 + tests/testthat/test-set_order.R | 2 +- tests/testthat/test-validate_input.R | 30 +++++++++---------- 9 files changed, 56 insertions(+), 46 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index df65c02..53bd57b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: vistime Title: Pretty Timelines in R -Version: 1.2.3 -Date: 2022-10-16 +Version: 1.2.4 +Date: 2023-10-28 Authors@R: c( person("Sandro", "Raabe", , "sa.ra.online@posteo.de", role = c("aut", "cre")) ) @@ -17,13 +17,13 @@ Depends: R (>= 3.2.0) Imports: rlang, - assertive.types (>= 0.0-3), + assertthat (>= 0.1), plotly (>= 4.0.0), - ggplot2 (>= 2.0.0), + ggplot2 (>= 3.4.0), ggrepel (>= 0.7.0), RColorBrewer (>= 0.2.2) Encoding: UTF-8 -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Suggests: prettydoc, knitr, diff --git a/NAMESPACE b/NAMESPACE index 1b580db..4699adf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,11 +4,10 @@ export(gg_vistime) export(hc_vistime) export(vistime) export(vistime_data) -importFrom(assertive.types,assert_is_a_number) -importFrom(assertive.types,assert_is_a_string) -importFrom(assertive.types,assert_is_data.frame) -importFrom(assertive.types,assert_is_logical) -importFrom(assertive.types,assert_is_posixct) +importFrom(assertthat,assert_that) +importFrom(assertthat,is.flag) +importFrom(assertthat,is.string) +importFrom(assertthat,is.time) importFrom(ggplot2,aes) importFrom(ggplot2,coord_cartesian) importFrom(ggplot2,element_blank) diff --git a/NEWS.md b/NEWS.md index e9b6c76..856b83c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# vistime 1.2.4 +## Bugfixes +- Fix failing dependency by exchanging package usage of `assertive.types` with `assertthat` + # vistime 1.2.3 - keep group column order in case of factors (otherwise groups appear in order of appearance) (closes #27, thanks @kelly-sovacool) diff --git a/R/plot_ggplot.R b/R/plot_ggplot.R index 90aa570..ebb42da 100644 --- a/R/plot_ggplot.R +++ b/R/plot_ggplot.R @@ -75,7 +75,7 @@ plot_ggplot <- function(data, linewidth, title, show_labels, background_lines) { range_dat <- data[data$start != data$end, ] event_dat <- data[data$start == data$end, ] gg <- gg + - geom_segment(data = range_dat, size = lw) + + geom_segment(data = range_dat, linewidth = lw) + geom_point(data = event_dat, mapping = aes(fill = I(.data$col)), shape = 21, size = 0.7 * lw, colour = "black", stroke = 0.1) diff --git a/R/validate_input.R b/R/validate_input.R index ee7be3d..859cf15 100644 --- a/R/validate_input.R +++ b/R/validate_input.R @@ -10,11 +10,10 @@ #' @param title plot title #' @param show_labels logical #' @param background_lines interval of gray background lines -#' @importFrom assertive.types assert_is_a_string -#' @importFrom assertive.types assert_is_data.frame -#' @importFrom assertive.types assert_is_a_number -#' @importFrom assertive.types assert_is_logical -#' @importFrom assertive.types assert_is_posixct +#' @importFrom assertthat is.string +#' @importFrom assertthat is.flag +#' @importFrom assertthat assert_that +#' @importFrom assertthat is.time #' #' @return list of the data frame and column arguments, or an error #' @keywords internal @@ -76,21 +75,22 @@ validate_input <- function(data, col.event, col.start, col.end, col.group, col.c } if(length(.dots) > 0) message("The following unexpected arguments were ignored: ", paste(names(.dots), collapse = ", ")) - assert_is_a_string(col.start) - assert_is_a_string(col.end) - assert_is_a_string(col.event) - assert_is_a_string(col.group) - if(!is.null(col.tooltip)) assert_is_a_string(col.tooltip) - assert_is_logical(optimize_y) + assert_that(is.string(col.start)) + assert_that(is.string(col.end)) + assert_that(is.string(col.event)) + assert_that(is.string(col.group)) + + if(!is.null(col.tooltip)) assert_that(is.string(col.tooltip)) + assert_that(is.flag(optimize_y)) # missing if called from vistime_data - if(!missing(linewidth) && !is.null(linewidth)) assert_is_a_number(linewidth) - if(!missing(title) && !is.null(title)) assert_is_a_string(title) - if(!missing(show_labels)) assert_is_logical(show_labels) - if(!missing(background_lines) && !is.null(background_lines)) assert_is_a_number(background_lines) + if(!missing(linewidth) && !is.null(linewidth)) assert_that(is.numeric(linewidth)) + if(!missing(title) && !is.null(title)) assert_that(is.string(title)) + if(!missing(show_labels)) assert_that(is.flag(show_labels)) + if(!missing(background_lines) && !is.null(background_lines)) assert_that(is.numeric(background_lines)) - df <- tryCatch(as.data.frame(data, stringsAsFactors = F), error = function(e) assert_is_data.frame(data)) - assert_is_data.frame(df) + df <- tryCatch(as.data.frame(data, stringsAsFactors = F), error = function(e) assert_that(is.data.frame(data))) + assert_that(is.data.frame(df)) if (!col.start %in% names(df)) @@ -99,8 +99,13 @@ validate_input <- function(data, col.event, col.start, col.end, col.group, col.c if (sum(!is.na(df[[col.start]])) == 0) stop(paste0("error in column '", col.start, "': Please provide at least one point in time")) - df[[col.start]] <- tryCatch(as.POSIXct(df[[col.start]]), error = function(e) assert_is_posixct(df[[col.start]])) - assert_is_posixct(df[[col.start]]) + df[[col.start]] <- tryCatch(as.POSIXct(df[[col.start]]), error = function(e) assert_that(is.time(df[[col.start]]))) + assert_that(is.time(df[[col.start]])) + + if(!is.null(df[[col.end]])){ + df[[col.end]] <- tryCatch(as.POSIXct(df[[col.end]]), error = function(e) assert_that(is.time(df[[col.end]]))) + assert_that(is.time(df[[col.end]])) + } if (!col.event %in% names(df)){ message("Column '", col.event, "' not found in data. Defaulting to col.event='", col.start, "'") diff --git a/inst/WORDLIST b/inst/WORDLIST index db956e1..c5cd139 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,3 +1,4 @@ +assertthat bugfix bugfixes codecov diff --git a/tests/testthat.R b/tests/testthat.R index 3b7f2c2..e79f73c 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -3,3 +3,4 @@ library(testthat) # devtools::test() test_check("vistime") + diff --git a/tests/testthat/test-set_order.R b/tests/testthat/test-set_order.R index c1442ac..5f25025 100644 --- a/tests/testthat/test-set_order.R +++ b/tests/testthat/test-set_order.R @@ -13,7 +13,7 @@ show_labels <- TRUE background_lines <- NULL - l <- validate_input(dat, col.start, col.end, col.event, col.group, col.color, col.fontcolor, col.tooltip, optimize_y, linewidth, title, show_labels, background_lines, list()) + l <- validate_input(dat, col.event, col.start, col.end, col.group, col.color, col.fontcolor, col.tooltip, optimize_y, linewidth, title, show_labels, background_lines, list()) dat <- set_colors(l$data, col.color, col.fontcolor) dat <- fix_columns(dat, col.event, col.start, col.end, col.group, col.color, col.fontcolor, col.tooltip) return(dat) diff --git a/tests/testthat/test-validate_input.R b/tests/testthat/test-validate_input.R index b848da5..0499cf0 100644 --- a/tests/testthat/test-validate_input.R +++ b/tests/testthat/test-validate_input.R @@ -48,57 +48,57 @@ test_that("data formats", { expect_error(validate_input2(dat, col.start = "mystart"), "error in column 'mystart': Please provide at least one point in time") expect_error(validate_input2(tibble(), col.event = 1), - "col.event is not of class 'character'") + "col.event is not a string") expect_error(validate_input2(tibble(), col.end=1), - "col.end is not of class 'character'") + "col.end is not a string") expect_error(validate_input2(tibble(), col.event = 1, col.start=1), - "col.start is not of class 'character'") + "col.start is not a string") expect_error(validate_input2(tibble(), col.group=1), - "col.group is not of class 'character'") + "col.group is not a string") expect_error( - validate_input2(plotly::plot_ly()), "data is not of class 'data.frame'" + validate_input2(plotly::plot_ly()), "data is not a data.frame" ) expect_error( - validate_input2(dat, show_labels = NULL), "show_labels is not of class 'logical'" + validate_input2(dat, show_labels = NULL), "show_labels is not a flag" ) expect_error( - validate_input2(dat, show_labels = "yes"), "show_labels is not of class 'logical'" + validate_input2(dat, show_labels = "yes"), "show_labels is not a flag" ) expect_error( - validate_input2(dat, show_labels = "TRUE"), "show_labels is not of class 'logical'" + validate_input2(dat, show_labels = "TRUE"), "show_labels is not a flag" ) expect_error( - validate_input2(dat, background_lines = "11"), "background_lines is not of class 'numeric'" + validate_input2(dat, background_lines = "11"), "background_lines is not a numeric" ) expect_error( - validate_input2(dat, background_lines = TRUE), "background_lines is not of class 'numeric'" + validate_input2(dat, background_lines = TRUE), "background_lines is not a numeric" ) expect_error( validate_input2(data.frame(mystart = "20180101"), col.event = "mystart", col.start = "mystart"), - "is not of class 'POSIXct'" + "is not a POSIXt" ) expect_error( - validate_input2(dat, linewidth = "g"), "linewidth is not of class 'numeric'" + validate_input2(dat, linewidth = "g"), "linewidth is not a numeric" ) expect_error( - validate_input2(dat, linewidth = "5"), "linewidth is not of class 'numeric'" + validate_input2(dat, linewidth = "5"), "linewidth is not a numeric" ) expect_error( - validate_input2(dat, background_lines = TRUE), "background_lines is not of class 'numeric'" + validate_input2(dat, background_lines = TRUE), "background_lines is not a numeric" ) expect_error( - validate_input2(dat, title = ggplot2::ggtitle("test")), "title is not of class 'character'" + validate_input2(dat, title = ggplot2::ggtitle("test")), "title is not a string" ) })