-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow addition of custom objects #2309
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
Changes from 1 commit
5c79bdb
82f45c1
54b6769
810bd28
fd1df33
94093c0
60a7169
83e8d52
eda7ccd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
context("plot-construction") | ||
|
||
test_that("Custom object cannot be added without generic", { | ||
p <- ggplot() | ||
custom_object <- structure(list(), class = 'test_object') | ||
expect_error(p + custom_object, "Don't know how to add custom_object to a plot") | ||
}) | ||
|
||
test_that("Methods can be defined for adding custom objects", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can define the method inside the test, just to make things slightly cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason I’m having problems getting dispatch to work correctly in the test. Moving it out fixed it locally but it still throws an error on travis..? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any idea why methods defined inside test_that expressions are not being dispatched to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's something to do with the weird way in which S3 dispatch happens. I forget all the details, but just move it outside for now. |
||
p <- ggplot() | ||
custom_object <- structure(list(), class = 'test_object') | ||
add_to_ggplot.test_object <- function(object, p, objectname) { | ||
10 | ||
} | ||
expect_equal(p + custom_object, 10) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
plot
andobject_name
would be better argument names