Skip to content

Commit

Permalink
replace assertive package with assertthat
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Raabe committed Oct 28, 2023
1 parent 8d6ec8a commit 250ec55
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 46 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"))
)
Expand All @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion R/plot_ggplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
43 changes: 24 additions & 19 deletions R/validate_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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, "'")
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
assertthat
bugfix
bugfixes
codecov
Expand Down
1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ library(testthat)
# devtools::test()

test_check("vistime")

2 changes: 1 addition & 1 deletion tests/testthat/test-set_order.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions tests/testthat/test-validate_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
})

Expand Down

0 comments on commit 250ec55

Please sign in to comment.