object <- function(...) {
..params <- list(...)
fun <- function() {}
formals(fun) <- ..params
body(fun) <- substitute(
{
self <- list2env(..params)
lockEnvironment(self)
updates <- as.list(match.call()[-1L])
This file contains hidden or 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
| primef <- function(x) { | |
| x <- as.integer(x) | |
| if (x <= 1) { | |
| return(NaN) | |
| } | |
| res <- integer() | |
| while (x %% 2L == 0L) { | |
| res <- c(res, 2L) |
This file contains hidden or 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
| # set in options(name = value) | |
| # retrieved in fuj.options$name | |
| # when retrieved, runs getter | |
| fuj.options <- local({ | |
| self <- environment() | |
| optenv <- new.env() | |
| active <- function(name, default, getter) { | |
| makeActiveBinding( | |
| name, | |
| local({ |
.fibs <- new.env()
.fib <- function(n) {
name <- as.character(n)
get0(name, envir = .fibs) %||% assign(name, fibonocci(n), envir = .fibs)
}
fibonocci <- function(n = 0) {
n <- floor(n)arg <- function(sym, type, default) {
sym <- substitute(sym)
spec <- structure(
list(
sym = as.character(sym),
type = type
),
class = "arg"
)enumerate <- function(x, i = "i", v = "v") {
lapply(
seq_along(x),
function(iteration) {
structure(
list(iteration, x[[iteration]]),
class = c("enumeration", "list"),
names = c(i, v)
)
This file contains hidden or 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
| global_calling_handlers <- local({ | |
| . <- environment() | |
| class(.) <- c("cnd:global_calling_handlers", "environment") | |
| .handlers <- NULL | |
| handlers <- NULL | |
| add <- function(...) { | |
| "Adds calling handlers | |
| If handlers with the same name already exist, they are replaced. |
This file contains hidden or 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
| pkg_version <- function(package, keep = c("all", "patch", "minor", "major")) { | |
| keep <- match.arg(keep) | |
| version <- utils::packageVersion(package) | |
| version <- unclass(version)[[1L]] | |
| version <- switch( | |
| keep, | |
| all = version, | |
| patch = version[1:3], | |
| minor = version[1:2], | |
| major = version[1L] |
This file contains hidden or 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
| pak_install_pkgs <- function( | |
| pkg, | |
| new_lib = old_lib, | |
| old_lib = .libPaths()[1L], | |
| upgrade = FALSE, | |
| update = TRUE, | |
| dependencies = NA, | |
| force = FALSE, | |
| use_temp = FALSE, | |
| pak_lib = NULL |
library(S7)
typed <- function(fun, ...) {
..params <- list(...)
..syms <- names(..params)
stopifnot(..syms %in% names(formals(fun)))
# should make this a function
..validator <- S7::new_class("..validator", properties = ..params)NewerOlder