-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big README updated, methods are solid
- Loading branch information
Matthew T. Warkentin
committed
Dec 21, 2020
1 parent
c41592b
commit 989d11c
Showing
27 changed files
with
701 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method("!=",R6) | ||
S3method("$",R6) | ||
S3method("$<-",R6) | ||
S3method("%%",R6) | ||
S3method("%/%",R6) | ||
S3method("*",R6) | ||
S3method("+",R6) | ||
S3method("-",R6) | ||
S3method("/",R6) | ||
S3method("<",R6) | ||
S3method("<=",R6) | ||
S3method("==",R6) | ||
S3method(">",R6) | ||
S3method(">=",R6) | ||
S3method("[",R6) | ||
S3method("[<-",R6) | ||
S3method("[[",R6) | ||
S3method("[[<-",R6) | ||
S3method("^",R6) | ||
S3method(all,equal.R6) | ||
S3method(as.data.frame,R6) | ||
S3method(length,R6) | ||
S3method(names,R6) | ||
S3method(str,R6) | ||
export(is.iterable) | ||
export(iter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,76 @@ | ||
`+.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".add"))) { | ||
.subset2(..1, ".add")(..2) | ||
#' @export | ||
`+.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__add__"))) { | ||
.subset2(e1, ".__add__")(e2) | ||
} else { | ||
rlang::abort( | ||
glue("No `+` method defined for R6 instance") | ||
paste0("No `+` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} | ||
|
||
`-.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".sub"))) { | ||
.subset2(..1, ".sub")(..2) | ||
#' @export | ||
`-.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__sub__"))) { | ||
.subset2(e1, ".__sub__")(e2) | ||
} else { | ||
rlang::abort( | ||
glue("No `-` method defined for R6 instance") | ||
paste0("No `-` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} | ||
|
||
`*.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".mul"))) { | ||
.subset2(..1, ".mul")(..2) | ||
#' @export | ||
`*.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__mul__"))) { | ||
.subset2(e1, ".__mul__")(e2) | ||
} else { | ||
rlang::abort( | ||
glue("No `*` method defined for R6 instance") | ||
paste0("No `*` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} | ||
|
||
`/.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".div"))) { | ||
.subset2(..1, ".div")(..2) | ||
#' @export | ||
`/.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__div__"))) { | ||
.subset2(e1, ".__div__")(e2) | ||
} else { | ||
rlang::abort( | ||
glue("No `/` method defined for R6 instance") | ||
paste0("No `/` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} | ||
|
||
`^.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".pow"))) { | ||
.subset2(..1, ".pow")(..2) | ||
#' @export | ||
`^.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__pow__"))) { | ||
.subset2(e1, ".__pow__")(e2) | ||
} else { | ||
rlang::abort( | ||
glue("No `^` method defined for R6 instance") | ||
paste0("No `^` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} | ||
|
||
`**.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".pow"))) { | ||
.subset2(..1, ".pow")(..2) | ||
#' @export | ||
`%%.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__mod__"))) { | ||
.subset2(e1, ".__mod__")(e2) | ||
} else { | ||
rlang::abort( | ||
glue("No `^` method defined for R6 instance") | ||
paste0("No `%%` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} | ||
|
||
`%%.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".mod"))) { | ||
.subset2(..1, ".mod")(..2) | ||
#' @export | ||
`%/%.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__intdiv__"))) { | ||
.subset2(e1, ".__intdiv__")(e2) | ||
} else { | ||
rlang::abort( | ||
glue("No `%%` method defined for R6 instance") | ||
paste0("No `%/%` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} | ||
|
||
`%/%.R6` <- function(...) { | ||
if (is.function(.subset2(..1, ".intdiv"))) { | ||
.subset2(..1, ".intdiv")(..2) | ||
} else { | ||
rlang::abort( | ||
glue("No `%/%` method defined for R6 instance") | ||
) | ||
} | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#' @export | ||
as.data.frame.R6 <- function(x, ...) { | ||
if (is.function(.subset2(x, ".__data__"))) { | ||
.subset2(x, ".__data__")(...) | ||
} else { | ||
NextMethod("as.data.frame", x) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
iter <- function() { | ||
NULL | ||
#' Make R6 Instance Iterable | ||
#' | ||
#' @description This function uses `coro` to create a generator. | ||
#' Using the returned object (a function), you can call this function to | ||
#' create an iterator. The iterator can be called repeatedly | ||
#' to produce batches of data. When all of the batches have been produced, | ||
#' the function will return the symbol `exhausted` for each call thereafter. | ||
#' | ||
#' @details A `coro` iterator is compatible with `for` loops via the | ||
#' `coro::loop()` function. `coro::collect()` can be used to collect the. | ||
#' next `n` set of batches. Leaving `n` blank will drain all of the remaining | ||
#' batches (assuming `length(x)` is not infinite). See `coro` | ||
#' documentation for more details. | ||
#' | ||
#' @param x `R6` object. | ||
#' | ||
#' @export | ||
iter <- function(x) { | ||
stopifnot(inherits(x, "R6")) | ||
stopifnot( | ||
is.function(.subset2(x, ".__length__")), | ||
is.function(.subset2(x, ".__getitem__")) | ||
) | ||
coro::generator( | ||
function() { | ||
for (i in 1:x$.__length__()) { | ||
coro::yield(x$.__getitem__(i)) | ||
} | ||
} | ||
) | ||
} | ||
|
||
is.iter <- function() { | ||
NULL | ||
#' @export | ||
#' @rdname iter | ||
is.iterable <- function(x) { | ||
if ( | ||
is.function(.subset2(x, ".__length__")) & | ||
is.function(.subset2(x, ".__getitem__")) | ||
) { | ||
TRUE | ||
} else { | ||
FALSE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
length | ||
str | ||
summary | ||
autoplot | ||
with | ||
seq | ||
format | ||
as.list | ||
is.na | ||
anyNA | ||
#' @export | ||
length.R6 <- function(x) { | ||
if (is.function(.subset2(x, ".__length__"))) { | ||
.subset2(x, ".__length__")() | ||
} else { | ||
NextMethod("length", x) | ||
} | ||
} | ||
|
||
#' @export | ||
names.R6 <- function(x) { | ||
if (is.function(.subset2(x, ".__names__"))) { | ||
.subset2(x, ".__names__")() | ||
} else { | ||
NextMethod("names", x) | ||
} | ||
} | ||
|
||
#' @export | ||
str.R6 <- function(object, ...) { | ||
if (is.function(.subset2(object, ".__str__"))) { | ||
do.call(.subset2(object, ".__str__"), args = list(...)) | ||
} else { | ||
NextMethod("str", object) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,76 @@ | ||
`<` | ||
`>` | ||
`<=` | ||
`>=` | ||
`==` | ||
`!=` | ||
all.equal | ||
#' @export | ||
`<.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__lt__"))) { | ||
.subset2(e1, ".__lt__")(e2) | ||
} else { | ||
rlang::abort( | ||
paste0("No `<` method defined for R6 instance") | ||
) | ||
} | ||
} | ||
|
||
#' @export | ||
`>.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__gt__"))) { | ||
.subset2(e1, ".__gt__")(e2) | ||
} else { | ||
rlang::abort( | ||
paste0("No `>` method defined for R6 instance") | ||
) | ||
} | ||
} | ||
|
||
#' @export | ||
`<=.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__le__"))) { | ||
.subset2(e1, ".__le__")(e2) | ||
} else { | ||
rlang::abort( | ||
paste0("No `<=` method defined for R6 instance") | ||
) | ||
} | ||
} | ||
|
||
#' @export | ||
`>=.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__ge__"))) { | ||
.subset2(e1, ".__ge__")(e2) | ||
} else { | ||
rlang::abort( | ||
paste0("No `>=` method defined for R6 instance") | ||
) | ||
} | ||
} | ||
|
||
#' @export | ||
`==.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__eq__"))) { | ||
.subset2(e1, ".__eq__")(e2) | ||
} else { | ||
rlang::abort( | ||
paste0("No `==` method defined for R6 instance") | ||
) | ||
} | ||
} | ||
|
||
#' @export | ||
`!=.R6` <- function(e1, e2) { | ||
if (is.function(.subset2(e1, ".__ne__"))) { | ||
.subset2(e1, ".__ne__")(e2) | ||
} else { | ||
rlang::abort( | ||
paste0("No `!=` method defined for R6 instance") | ||
) | ||
} | ||
} | ||
|
||
#' @export | ||
`all.equal.R6` <- function(target, current, ...) { | ||
if (is.function(.subset2(target, ".__ae__"))) { | ||
.subset2(target, ".__ae__")(current, ...) | ||
} else { | ||
rlang::abort( | ||
paste0("No `all.equal` method defined for R6 instance") | ||
) | ||
} | ||
} |
Oops, something went wrong.