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

added type checks for new_object() argument .parent #503

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions R/class.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ is_class <- function(x) inherits(x, "S7_class")

# Object ------------------------------------------------------------------

#' @param .parent,... Parent object and named properties used to construct the
#' object.
#' @param .parent,... Parent S7 object and named properties used to construct
Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessarily an S7 object, because the class might extend a base class.

#' the object.
#' @rdname new_class
#' @export
new_object <- function(.parent, ...) {
Expand All @@ -253,7 +253,15 @@ new_object <- function(.parent, ...) {
}

# force .parent before ...
# TODO: Some type checking on `.parent`?
# TODO: Some additional type checking on `.parent`?

if (!inherits(.parent, "S7_object"))
stop("`.parent` needs to be an S7_object")
if (inherits(.parent, "S7_class")) {
stop(paste("`.parent` cannot be of type S7_class. Did you type",
Copy link
Member

Choose a reason for hiding this comment

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

Can you please put this on two lines and add a snapshot test for it?

"`.parent = S7_object` instead of `.parent = S7_object()`?"))
}

object <- .parent

args <- list(...)
Expand Down
Loading