From 61d076de5ed325f0ee83f9e084edbc4e0ae9982c Mon Sep 17 00:00:00 2001 From: Richard Cotton Date: Sun, 18 Sep 2016 10:41:50 +0300 Subject: [PATCH] added is* fns --- NAMESPACE | 3 +++ R/is.R | 39 +++++++++++++++++++++++++++++++++++++++ man/is.r6.Rd | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 R/is.R create mode 100644 man/is.r6.Rd diff --git a/NAMESPACE b/NAMESPACE index f6baf8b..e6159bd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,3 +7,6 @@ S3method(plot,R6) S3method(print,R6) S3method(print,R6ClassGenerator) export(R6Class) +export(is.r6) +export(is.r6gen) +export(is.r6obj) diff --git a/R/is.R b/R/is.R new file mode 100644 index 0000000..d882ce2 --- /dev/null +++ b/R/is.R @@ -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") +} diff --git a/man/is.r6.Rd b/man/is.r6.Rd new file mode 100644 index 0000000..95d4266 --- /dev/null +++ b/man/is.r6.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/is.R +\name{is.r6} +\alias{is.r6} +\alias{is.r6gen} +\alias{is.r6obj} +\title{Is an object an R6 Class Generator or Object?} +\usage{ +is.r6(x) + +is.r6obj(x) + +is.r6gen(x) +} +\arguments{ +\item{x}{Any variable.} +} +\value{ +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. +} +\description{ +Checks for R6 class generators and R6 objects. +} +\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) +} +