Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #101 - throw an error if the x argument supplied to vis_dat is not a data.frame #102

Merged
merged 5 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions R/vis-dat.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ vis_dat <- function(x,
warn_large_data = TRUE,
large_data_size = 900000) {

# throw error if x not data.frame
if(!(inherits(x, "data.frame"))){
stop("vis_dat requires a data.frame but the object I see has class/es: ",
paste(class(x), collapse = ", "))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the option for stop, call. = FALSE, as is done in the naniar function :)

}

# add warning for large data
if (ncol(x) * nrow(x) > large_data_size && warn_large_data){
stop("Data exceeds recommended size for visualisation, please consider
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-vis-dat.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ test_that("vis_dat fails when the wrong palette is provided",{
cat(sprintf("FreeType version: %s\n", ver))
expect_error(vis_dat(typical_data, palette = "wat"))
})

test_that("vis_dat fails when an object of the wrong class is provided", {
expect_error(vis_dat(AirPassengers))
})