Skip to content

Commit

Permalink
added is* fns
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Cotton committed Sep 18, 2016
1 parent 9ca3108 commit 61d076d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ S3method(plot,R6)
S3method(print,R6)
S3method(print,R6ClassGenerator)
export(R6Class)
export(is.r6)
export(is.r6gen)
export(is.r6obj)
39 changes: 39 additions & 0 deletions R/is.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' Is an object an R6 Class Generator or Object?
#'
#' Checks for R6 class generators and R6 objects.
#' @param x Any variable.
#' @return A logical value.
#' \code{is.r6} returns \code{TRUE} when the input is an R6 class generator or
#' an R6 object, and \code{FALSE} otherwise.
#' \code{is.r6gen} returns \code{TRUE} when the input is an R6 class generator
#' and \code{FALSE} otherwise.
#' \code{is.r6obj} returns \code{TRUE} when the input is an R6 object and
#' \code{FALSE} otherwise.
#' @examples
#' class_generator <- R6::R6Class()
#' object <- class_generator$new()
#' is.r6(class_generator)
#' is.r6gen(class_generator)
#' is.r6obj(class_generator)
#' is.r6(object)
#' is.r6gen(object)
#' is.r6obj(object)
#' @export
is.r6 <- function(x)
{
is.r6obj(x) || is.r6gen(x)
}

#' @rdname is.r6
#' @export
is.r6obj <- function(x)
{
inherits(x, "R6")
}

#' @rdname is.r6
#' @export
is.r6gen <- function(x)
{
inherits(x, "R6ClassGenerator")
}
40 changes: 40 additions & 0 deletions man/is.r6.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61d076d

Please sign in to comment.