├── .Rbuildignore ├── .gitignore ├── tests ├── testthat.R └── testthat │ ├── test-basic.R │ ├── test-accessing.R │ └── test-methods.R ├── docs ├── pkgdown.yml ├── link.svg ├── docsearch.js ├── pkgdown.js ├── articles │ ├── index.html │ └── Introduction.html ├── authors.html ├── pkgdown.css ├── reference │ ├── is.enum_value.html │ ├── get_enum_values.html │ ├── add_enum_methods.html │ ├── get_enum_method.html │ ├── methodize.html │ ├── apply_enum_method.html │ ├── print.enum_value.html │ ├── cash-.enum_type.html │ ├── sub-.enum_type.html │ ├── subset-.enum_type.html │ ├── cash-set-.enum_type.html │ ├── print.enum_type.html │ ├── as.enum_type.html │ ├── get_enum_index.html │ ├── enum_type.html │ ├── is.enum_type.html │ ├── sample_enum.html │ └── index.html ├── index.html └── docsearch.css ├── R ├── names.enum_type.R ├── length.enum_type.R ├── get_enum_values.R ├── print.enum_value.R ├── enum_list.R ├── apply_enum_method.R ├── summary.enum_type.R ├── print.enum_type.R ├── enum_value.R ├── get_enum_index.R ├── is.enum_value.R ├── get_enum_method.R ├── sample_enum.R ├── add_enum_methods.R ├── match_enum_value.R ├── accessing_enum_values.R ├── as.enum_type.R ├── is.enum_type.R └── enum_type.R ├── man ├── is.enum_value.Rd ├── get_enum_values.Rd ├── methodize.Rd ├── add_enum_methods.Rd ├── get_enum_method.Rd ├── print.enum_value.Rd ├── apply_enum_method.Rd ├── match_enum_value.Rd ├── cash-.enum_type.Rd ├── sub-.enum_type.Rd ├── print.enum_type.Rd ├── subset-.enum_type.Rd ├── cash-set-.enum_type.Rd ├── as.enum_type.Rd ├── get_enum_index.Rd ├── enum_type.Rd ├── is.enum_type.Rd └── sample_enum.Rd ├── .travis.yml ├── NAMESPACE ├── DESCRIPTION ├── README.md └── vignettes └── Introduction.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user/ 2 | *.Rproj 3 | .Rbuildignore 4 | .Rhistory 5 | .Rproj.user 6 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(enumeR) 3 | 4 | test_check("enumeR") 5 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.7.2 2 | pkgdown: 1.3.0 3 | pkgdown_sha: ~ 4 | articles: 5 | Introduction: Introduction.html 6 | 7 | -------------------------------------------------------------------------------- /R/names.enum_type.R: -------------------------------------------------------------------------------- 1 | names.enum_type <- function(enum_type) { 2 | stopifnot(is.enum_type(enum_type)) 3 | enum_type[["type_name"]] 4 | } 5 | -------------------------------------------------------------------------------- /R/length.enum_type.R: -------------------------------------------------------------------------------- 1 | length.enum_type <- function(enum_type) { 2 | stopifnot(is.enum_type(enum_type)) 3 | length(get_enum_values(enum_type)) 4 | } 5 | -------------------------------------------------------------------------------- /R/get_enum_values.R: -------------------------------------------------------------------------------- 1 | #' TEMPORARRY DOCUMENTATION 2 | #' 3 | #' @description TEMPORARY DOCUMENTATION 4 | #' 5 | #' @export 6 | 7 | get_enum_values <- function(enum_type) { 8 | stopifnot(is.enum_type(enum_type)) 9 | enum_type[["values"]] 10 | } 11 | -------------------------------------------------------------------------------- /R/print.enum_value.R: -------------------------------------------------------------------------------- 1 | #' TEMPORARRY DOCUMENTATION 2 | #' 3 | #' @description TEMPORARY DOCUMENTATION 4 | #' 5 | #' @export 6 | 7 | print.enum_value <- function(enum_value) { 8 | cat(get_enum_index(enum_value), " : ", enum_value$value_name, "\n") 9 | } 10 | -------------------------------------------------------------------------------- /R/enum_list.R: -------------------------------------------------------------------------------- 1 | enum_list <- function(list) { 2 | stopifnot(all(sapply(list, is.enum_value))) 3 | class(list) <- c(class(list), "enum_list") 4 | list 5 | } 6 | 7 | print.enum_list <- function(enum_list) { 8 | cat("List of enum values:\n") 9 | invisible(sapply(enum_list, print)) 10 | } 11 | -------------------------------------------------------------------------------- /man/is.enum_value.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is.enum_value.R 3 | \name{is.enum_value} 4 | \alias{is.enum_value} 5 | \title{TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | is.enum_value(object) 8 | } 9 | \description{ 10 | TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /R/apply_enum_method.R: -------------------------------------------------------------------------------- 1 | #' TEMPORARRY DOCUMENTATION 2 | #' 3 | #' @description TEMPORARY DOCUMENTATION 4 | #' 5 | #' @export 6 | apply_enum_method <- function(enum_value, method, ...) { 7 | eval(enum_value$methods_env$methods_universal[[as.character(substitute(method))]])(...) 8 | } 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /man/get_enum_values.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_enum_values.R 3 | \name{get_enum_values} 4 | \alias{get_enum_values} 5 | \title{TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | get_enum_values(enum_type) 8 | } 9 | \description{ 10 | TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /man/methodize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_enum_methods.R 3 | \name{methodize} 4 | \alias{methodize} 5 | \title{@title TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | methodize(enum_type, method) 8 | } 9 | \description{ 10 | @description TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /man/add_enum_methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_enum_methods.R 3 | \name{add_enum_methods} 4 | \alias{add_enum_methods} 5 | \title{TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | add_enum_methods(enum_type, ...) 8 | } 9 | \description{ 10 | TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /man/get_enum_method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_enum_method.R 3 | \name{get_enum_method} 4 | \alias{get_enum_method} 5 | \title{TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | get_enum_method(enum_value, method) 8 | } 9 | \description{ 10 | TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | cache: packages 3 | 4 | r: 5 | - oldrel 6 | - release 7 | - devel 8 | 9 | r_packages: 10 | - covr 11 | 12 | warnings_are_errors: false 13 | 14 | notifications: 15 | email: 16 | on_success: change 17 | on_failure: change 18 | 19 | after_success: 20 | - Rscript -e 'covr::codecov()' 21 | -------------------------------------------------------------------------------- /man/print.enum_value.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/print.enum_value.R 3 | \name{print.enum_value} 4 | \alias{print.enum_value} 5 | \title{TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | \method{print}{enum_value}(enum_value) 8 | } 9 | \description{ 10 | TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /man/apply_enum_method.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/apply_enum_method.R 3 | \name{apply_enum_method} 4 | \alias{apply_enum_method} 5 | \title{TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | apply_enum_method(enum_value, method, ...) 8 | } 9 | \description{ 10 | TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /man/match_enum_value.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/match_enum_value.R 3 | \name{match_enum_value} 4 | \alias{match_enum_value} 5 | \title{TEMPORARRY DOCUMENTATION} 6 | \usage{ 7 | match_enum_value(x, table, nomatch = NA_integer_, incomparables = NULL) 8 | } 9 | \description{ 10 | TEMPORARY DOCUMENTATION 11 | } 12 | -------------------------------------------------------------------------------- /R/summary.enum_type.R: -------------------------------------------------------------------------------- 1 | summary.enum_type <- function(object, ...) { 2 | if (!is.enum_type(object)) { 3 | return(summary.default(object, ...)) 4 | } 5 | value <- array("", c(2L, 1L), list(c("Values", "Methods"), "Length")) 6 | value[1L, 1L] <- length(get_enum_values(object)) 7 | value[2L, 1L] <- length(object[["methods"]]) 8 | class(value) <- c("table") 9 | value 10 | } 11 | -------------------------------------------------------------------------------- /R/print.enum_type.R: -------------------------------------------------------------------------------- 1 | #' Print enum_type 2 | #' 3 | #' @description Pretty prints enum_type object. Overloads default print. 4 | #' 5 | #' @param enum_type Object of class enum_type 6 | #' 7 | #' @export 8 | 9 | print.enum_type <- function(enum_type) { 10 | cat("Enum type: ", enum_type[["type_name"]], 11 | "\n\nValues:\n") 12 | invisible(sapply(enum_type[["values"]], print)) 13 | } 14 | -------------------------------------------------------------------------------- /R/enum_value.R: -------------------------------------------------------------------------------- 1 | ##not exported 2 | 3 | enum_value <- function(enum_type, methods_env, value_name, index, fields = list()) { 4 | value <- c(list(type_name = enum_type, 5 | methods_env = methods_env, 6 | value_name = value_name, 7 | index = index), 8 | fields) 9 | class(value) <- "enum_value" 10 | value 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /man/cash-.enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/accessing_enum_values.R 3 | \name{$.enum_type} 4 | \alias{$.enum_type} 5 | \title{Get subset of values of enum_type} 6 | \usage{ 7 | \method{$}{enum_type}(enum_type, value) 8 | } 9 | \arguments{ 10 | \item{enum_type}{enum_type} 11 | 12 | \item{index}{index} 13 | } 14 | \description{ 15 | placeholder 16 | } 17 | -------------------------------------------------------------------------------- /man/sub-.enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/accessing_enum_values.R 3 | \name{[.enum_type} 4 | \alias{[.enum_type} 5 | \title{Get subset of values of enum_type} 6 | \usage{ 7 | \method{[}{enum_type}(enum_type, index) 8 | } 9 | \arguments{ 10 | \item{enum_type}{enum_type} 11 | 12 | \item{index}{index} 13 | } 14 | \description{ 15 | placeholder 16 | } 17 | -------------------------------------------------------------------------------- /man/print.enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/print.enum_type.R 3 | \name{print.enum_type} 4 | \alias{print.enum_type} 5 | \title{Print enum_type} 6 | \usage{ 7 | \method{print}{enum_type}(enum_type) 8 | } 9 | \arguments{ 10 | \item{enum_type}{Object of class enum_type} 11 | } 12 | \description{ 13 | Pretty prints enum_type object. Overloads default print. 14 | } 15 | -------------------------------------------------------------------------------- /man/subset-.enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/accessing_enum_values.R 3 | \name{[<-.enum_type} 4 | \alias{[<-.enum_type} 5 | \title{Get subset of values of enum_type} 6 | \usage{ 7 | \method{[}{enum_type}(enum_type, index) <- value 8 | } 9 | \arguments{ 10 | \item{enum_type}{enum_type} 11 | 12 | \item{index}{index} 13 | } 14 | \description{ 15 | placeholder 16 | } 17 | -------------------------------------------------------------------------------- /man/cash-set-.enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/accessing_enum_values.R 3 | \name{$<-.enum_type} 4 | \alias{$<-.enum_type} 5 | \title{Get subset of values of enum_type} 6 | \usage{ 7 | \method{$}{enum_type}(enum_type, index) <- value 8 | } 9 | \arguments{ 10 | \item{enum_type}{enum_type} 11 | 12 | \item{index}{index} 13 | } 14 | \description{ 15 | placeholder 16 | } 17 | -------------------------------------------------------------------------------- /man/as.enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/as.enum_type.R 3 | \name{as.enum_type} 4 | \alias{as.enum_type} 5 | \title{Coerce to an enum type} 6 | \usage{ 7 | as.enum_type(x) 8 | } 9 | \arguments{ 10 | \item{x}{any R object} 11 | } 12 | \value{ 13 | Object of class \code{\link{enum_type}} 14 | } 15 | \description{ 16 | Functions to check if an object is an enum type, or coerce it if possible. 17 | } 18 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method("$",enum_type) 4 | S3method("$<-",enum_type) 5 | S3method("[",enum_type) 6 | S3method("[<-",enum_type) 7 | S3method(print,enum_type) 8 | S3method(print,enum_value) 9 | export(add_enum_methods) 10 | export(apply_enum_method) 11 | export(as.enum_type) 12 | export(enum_type) 13 | export(get_enum_index) 14 | export(get_enum_method) 15 | export(get_enum_values) 16 | export(is.enum_type) 17 | export(is.enum_value) 18 | export(match_enum_value) 19 | export(sample_enum) 20 | -------------------------------------------------------------------------------- /man/get_enum_index.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_enum_index.R 3 | \name{get_enum_index} 4 | \alias{get_enum_index} 5 | \title{Get Enum Index} 6 | \usage{ 7 | get_enum_index(enum_value) 8 | } 9 | \arguments{ 10 | \item{enum_value}{object of class `enum_value` or list of such objects with the same `enum_type`} 11 | } 12 | \value{ 13 | integer index of `enum_value` or named vector of integers coresponding to values in list 14 | } 15 | \description{ 16 | Extracts `index` attribute value of passed `enum_value`. 17 | } 18 | -------------------------------------------------------------------------------- /R/get_enum_index.R: -------------------------------------------------------------------------------- 1 | #' Get Enum Index 2 | #' 3 | #' @description Extracts `index` attribute value of passed `enum_value`. 4 | #' 5 | #' @param enum_value object of class `enum_value` or list of such objects with the same `enum_type` 6 | #' 7 | #' @return integer index of `enum_value` or named vector of integers coresponding to values in list 8 | #' 9 | #' @export 10 | 11 | get_enum_index <- function(enum_value) { 12 | stopifnot(is.enum_value(enum_value)) 13 | if(is.enum_value(enum_value)) { 14 | enum_value$index 15 | } else { 16 | sapply(enum_value, function(value) value$index) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /man/enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/enum_type.R 3 | \name{enum_type} 4 | \alias{enum_type} 5 | \title{Enum type} 6 | \usage{ 7 | enum_type(type_name, values_names, ...) 8 | } 9 | \arguments{ 10 | \item{type_name}{Character vector of length 1. Name of the type. Type name will be referenced by this value} 11 | 12 | \item{...}{Optional other fields that are used during constructing enum_values} 13 | 14 | \item{value_names}{Character vector of positive length. Possible names of enum_values (instances)} 15 | } 16 | \description{ 17 | Creates new enum type. 18 | } 19 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: enumeR 2 | Title: Enum types support for R 3 | Version: 0.0.0.9000 4 | Authors@R: c( 5 | person("Dominik", 6 | "Rafacz", 7 | role = c("aut", "cre"), 8 | email = "d.rafacz@student.mini.pw.edu.pl"), 9 | person("Mateusz", 10 | "Bąkała", 11 | role = "aut", 12 | email = "m.bakala2@student.mini.pw.edu.pl") 13 | ) 14 | Description: This package provides tools for creating and using enumeration types (enums). 15 | License: GPL 16 | Encoding: UTF-8 17 | LazyData: true 18 | RoxygenNote: 6.1.1 19 | Suggests: 20 | knitr, 21 | rmarkdown, 22 | testthat (>= 2.1.0) 23 | VignetteBuilder: knitr 24 | -------------------------------------------------------------------------------- /R/is.enum_value.R: -------------------------------------------------------------------------------- 1 | #' TEMPORARRY DOCUMENTATION 2 | #' 3 | #' @description TEMPORARY DOCUMENTATION 4 | #' 5 | #' @export 6 | 7 | is.enum_value <- function(object) { 8 | if(class(object) == "enum_value" && 9 | !any(is.null(object$type_name), 10 | is.null(object$value_name), 11 | is.null(object$index), 12 | is.null(object$methods_env)) && 13 | all(is.character(object$type_name), 14 | is.character(object$value_name), 15 | is.integer(object$index), 16 | is.environment(object$methods_env)) && 17 | all(length(object$type_name) == 1, 18 | length(object$value_name) == 1, 19 | length(object$index == 1))){ 20 | return(TRUE) 21 | } 22 | return(FALSE) 23 | } 24 | -------------------------------------------------------------------------------- /man/is.enum_type.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/is.enum_type.R 3 | \name{is.enum_type} 4 | \alias{is.enum_type} 5 | \title{Test if the object is an enum type} 6 | \usage{ 7 | is.enum_type(object) 8 | } 9 | \value{ 10 | \code{TRUE} if the object passed all tests described above, \code{FALSE} otherwise. 11 | } 12 | \description{ 13 | This function checks class of passed object. If vector of classes contains 14 | \code{"enum_type"}, then checks if all necessary fields are not \code{null}, namely 15 | \code{type_name} and \code{values}, and whether \code{type_name} is a singular 16 | character vector. Next, checks if \code{fields_names} is a character vector or \code{null}. 17 | Lastly, all values need to be unique and proper \code{enum_value} objects. 18 | } 19 | -------------------------------------------------------------------------------- /R/get_enum_method.R: -------------------------------------------------------------------------------- 1 | #' TEMPORARRY DOCUMENTATION 2 | #' 3 | #' @description TEMPORARY DOCUMENTATION 4 | #' 5 | #' @export 6 | 7 | get_enum_method <- function(enum_value, method) { 8 | method_name <- as.character(substitute(method)) 9 | methods_names <- names(enum_value$methods_env$methods_universal) 10 | if(!method_name %in% methods_names) { 11 | stop(method_name, " is not a proper name of any of ", enum_value$type_name, " methods!") 12 | } 13 | method <- enum_value$methods_env$methods_universal[[method_name]] 14 | variables <- names(enum_value)[-c(1,2)] 15 | variables_w_d <- paste(".", variables, sep = "") 16 | inds <- match(variables_w_d, names(formals(method))) 17 | formals(method)[inds] <- enum_value[-c(1,2)] 18 | ret <- function(...) { 19 | method(...) 20 | } 21 | #formals(ret) <- formals(method)[-inds] 22 | ret 23 | } 24 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /man/sample_enum.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sample_enum.R 3 | \name{sample_enum} 4 | \alias{sample_enum} 5 | \title{Sample n values from an enum type} 6 | \usage{ 7 | sample_enum(enum_type, size, replace = FALSE, weight = NULL) 8 | } 9 | \arguments{ 10 | \item{enum_type}{Object that passes [is.enum_type()] check.} 11 | 12 | \item{size}{A non-negative integer giving number of items to choose.} 13 | 14 | \item{replace}{Should sampling be with replacement?} 15 | 16 | \item{weight}{Sampling weights. This must evaluate to a vector of non-negative numbers the same 17 | length as the input. Weights are automatically standardised to sum to 1.} 18 | } 19 | \value{ 20 | A list of enum values of length \code{size} drawn from \code{enum_type}'s values. 21 | } 22 | \description{ 23 | This is a wrapper around [sample()] to make selecting random enum values easier. 24 | } 25 | -------------------------------------------------------------------------------- /R/sample_enum.R: -------------------------------------------------------------------------------- 1 | #' Sample n values from an enum type 2 | #' 3 | #' @description This is a wrapper around [sample()] to make selecting random enum values easier. 4 | #' 5 | #' @param enum_type Object that passes [is.enum_type()] check. 6 | #' @param size A non-negative integer giving number of items to choose. 7 | #' @param replace Should sampling be with replacement? 8 | #' @param weight Sampling weights. This must evaluate to a vector of non-negative numbers the same 9 | #' length as the input. Weights are automatically standardised to sum to 1. 10 | #' 11 | #' @return A list of enum values of length \code{size} drawn from \code{enum_type}'s values. 12 | #' 13 | #' @export 14 | 15 | sample_enum <- function(enum_type, size, replace = FALSE, weight = NULL) { 16 | stopifnot(is.enum_type(enum_type)) 17 | if (!is.null(weight)) { 18 | weight <- weight/sum(weight) 19 | } 20 | enum_list(sample(enum_type[["values"]], size, replace, weight)) 21 | } 22 | -------------------------------------------------------------------------------- /R/add_enum_methods.R: -------------------------------------------------------------------------------- 1 | #' TEMPORARRY DOCUMENTATION 2 | #' 3 | #' @description TEMPORARY DOCUMENTATION 4 | #' 5 | #' @export 6 | add_enum_methods <- function(enum_type, ...) { 7 | added_methods <- match.call(expand.dots = FALSE)$`...` 8 | n <- length(added_methods) 9 | invisible( 10 | lapply(1:n, function(index) { 11 | enum_type[["methods_env"]]$methods_universal[[names(added_methods)[index]]] <- methodize(enum_type, eval(added_methods[[index]])) 12 | }) 13 | ) 14 | } 15 | 16 | 17 | #' @title TEMPORARRY DOCUMENTATION 18 | #' 19 | #' @description TEMPORARY DOCUMENTATION 20 | methodize <- function(enum_type, method) { 21 | variables <- paste(".", c("index", enum_type[["fields_names"]]), sep = "") 22 | if(is.null(formals(method))) { 23 | formals(method) <- alist(.value_name = ) 24 | } else { 25 | formals(method)[[".value_name"]] <- alist(x= )$x 26 | } 27 | for(var in variables) { 28 | formals(method)[[var]] <- alist(x = )$x 29 | } 30 | method 31 | } 32 | -------------------------------------------------------------------------------- /R/match_enum_value.R: -------------------------------------------------------------------------------- 1 | #' TEMPORARRY DOCUMENTATION 2 | #' 3 | #' @description TEMPORARY DOCUMENTATION 4 | #' 5 | #' @export 6 | match_enum_value <- function(x, table, nomatch = NA_integer_, incomparables = NULL) { 7 | stopifnot(is.enum_value(x) || all(sapply(x, is.enum_value))) 8 | if(is.enum_type(table)) { 9 | table <- get_enum_values(table) 10 | } else if (!all(sapply(table, is.enum_value))) { 11 | stop("table should be list of enum_values or enum_type") 12 | } 13 | if(is.enum_value(x)) { 14 | matched <- FALSE 15 | i <- 1 16 | while(!matched && i <= length(table)) { 17 | if (identical(x, table[[i]])) { 18 | matched <- TRUE 19 | } 20 | i <- i +1 21 | } 22 | ifelse(matched, i-1, NA_integer_) 23 | } else { 24 | sapply(x, function(val) { 25 | matched <- FALSE 26 | i <- 1 27 | while(!matched && i <= length(table)) { 28 | if (identical(val, table[[i]])) { 29 | matched <- TRUE 30 | } 31 | i <- i +1 32 | } 33 | ifelse(matched, i-1, NA_integer_) 34 | }) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # enumeR 2 | 3 | [![Build Status](https://travis-ci.org/DominikRafacz/enumeR.svg?branch=master)](https://travis-ci.org/DominikRafacz/enumeR) 4 | 5 | [![codecov](https://codecov.io/gh/DominikRafacz/enumeR/branch/master/graph/badge.svg)](https://codecov.io/gh/DominikRafacz/enumeR) 6 | 7 | [![stability-experimental](https://img.shields.io/badge/stability-experimental-orange.svg)](https://github.com/emersion/stability-badges#experimental) 8 | 9 | 10 | 11 | This package provides *enum_type* and *enum* classes, which allows to create and instantinize enumerable types in **R** 12 | 13 | It is in it's early development and authors don't grat any assurance that function names, parameters or functionalities won't change in future. 14 | 15 | # Installation 16 | 17 | To install this package you need to use `devtools` library, which can be installed with: 18 | ``` 19 | install.packages("devtools") 20 | ``` 21 | 22 | If you have already installed `devtools`, you need to run following code to install this package: 23 | 24 | ``` 25 | devtools::install_github("DominikRafacz/enumeR") 26 | ``` 27 | -------------------------------------------------------------------------------- /R/accessing_enum_values.R: -------------------------------------------------------------------------------- 1 | #' Get subset of values of enum_type 2 | #' 3 | #' @description placeholder 4 | #' 5 | #' @param enum_type enum_type 6 | #' @param index index 7 | #' 8 | #' @export 9 | "[.enum_type" <- function(enum_type, index) { 10 | enum_type[["values"]][index] 11 | } 12 | 13 | #' Get subset of values of enum_type 14 | #' 15 | #' @description placeholder 16 | #' 17 | #' @param enum_type enum_type 18 | #' @param index index 19 | #' 20 | #' @export 21 | "[<-.enum_type" <- function(enum_type, index, value) { 22 | stop("You cannot modify enum_type values!") 23 | } 24 | 25 | #' Get subset of values of enum_type 26 | #' 27 | #' @description placeholder 28 | #' 29 | #' @param enum_type enum_type 30 | #' @param index index 31 | #' 32 | #' @export 33 | "$.enum_type" <- function(enum_type, value) { 34 | enum_type[["values"]][[value]] 35 | } 36 | 37 | #' Get subset of values of enum_type 38 | #' 39 | #' @description placeholder 40 | #' 41 | #' @param enum_type enum_type 42 | #' @param index index 43 | #' 44 | #' @export 45 | "$<-.enum_type" <- function(enum_type, index, value) { 46 | stop("You cannot modify enum_type values!") 47 | } 48 | -------------------------------------------------------------------------------- /R/as.enum_type.R: -------------------------------------------------------------------------------- 1 | #' Coerce to an enum type 2 | #' 3 | #' @description Functions to check if an object is an enum type, or coerce it if possible. 4 | #' 5 | #' @param x any R object 6 | #' 7 | #' @return Object of class \code{\link{enum_type}} 8 | #' 9 | #' @export 10 | 11 | as.enum_type <- function(x) { 12 | stopifnot(!is.null(x), length(x) > 0) 13 | UseMethod("as.enum_type") 14 | } 15 | 16 | as.enum_type.default <- function(x) { 17 | stop(gettextf("cannot coerce class %s to an enum_type", sQuote(deparse(class(x))[1L])), 18 | domain = NA) 19 | } 20 | 21 | as.enum_type.list <- function(x) { 22 | stopifnot(length(x) > 0) 23 | 24 | type_name <- x$type_name 25 | type_name_ <- "type_name" 26 | if (is.null(type_name)) { 27 | type_name <- x$name 28 | type_name_ <- "name" 29 | if (is.null(type_name)) { 30 | type_name <- deparse(substitute(x)) 31 | type_name_ <- "" 32 | } 33 | } 34 | 35 | values <- x$values 36 | if (is.null(values)) { 37 | values <- x[[names(x)[which(names(x)[1] != type_name_)]]] 38 | } 39 | 40 | enum_type(type_name, values) 41 | } 42 | 43 | as.enum_type.character <- function(x) { 44 | stopifnot(length(x) > 0) 45 | if (length(unique(x)) != length(x)) { 46 | message("Warning: Vector has non-unique values. Repeated ones will be dropped") 47 | } 48 | enum_type(deparse(substitute(x)), unique(x)) 49 | } 50 | -------------------------------------------------------------------------------- /R/is.enum_type.R: -------------------------------------------------------------------------------- 1 | #' Test if the object is an enum type 2 | #' 3 | #' @description This function checks class of passed object. If vector of classes contains 4 | #' \code{"enum_type"}, then checks if all necessary fields are not \code{null}, namely 5 | #' \code{type_name} and \code{values}, and whether \code{type_name} is a singular 6 | #' character vector. Next, checks if \code{fields_names} is a character vector or \code{null}. 7 | #' Lastly, all values need to be unique and proper \code{enum_value} objects. 8 | #' 9 | #' @return \code{TRUE} if the object passed all tests described above, \code{FALSE} otherwise. 10 | #' 11 | #' @export 12 | 13 | is.enum_type <- function(object) { 14 | if("enum_type" %in% class(object) && 15 | !any(is.null(object[["type_name"]]), 16 | is.null(object[["values"]]), 17 | is.null(object[["methods_env"]])) && 18 | is.character(object[["type_name"]]) && 19 | is.environment(object[["methods_env"]]) && 20 | length(object[["type_name"]]) == 1 && 21 | (is.null(object[["fields_names"]]) || 22 | is.character(object[["fields_names"]]))) { 23 | values <- object[["values"]] 24 | n <- length(values) 25 | if (length(unique(values)) == n && 26 | all(unlist(lapply(values, is.enum_value)))) { 27 | #TO DO: add more tests, such as checking if all values have all fields 28 | return(TRUE) 29 | } 30 | } 31 | return(FALSE) 32 | } 33 | -------------------------------------------------------------------------------- /tests/testthat/test-basic.R: -------------------------------------------------------------------------------- 1 | test_that("enum_values are created properly", { 2 | temp <- new.env() 3 | object <- enum_value("animal", temp, "COW", 5L, list(voice = "mooo!", color = c("red", "white"))) 4 | reference <- list(type_name = "animal", 5 | methods_env = temp, 6 | value_name = "COW", 7 | index = 5, 8 | voice = "mooo!", 9 | color = c("red", "white")) 10 | class(reference) <- "enum_value" 11 | expect_equal(object, reference) 12 | }) 13 | 14 | test_that("enum_types with no fields are created properly", { 15 | object <- enum_type("animal", 16 | c("DOG", "CAT", "COW")) 17 | temp <- object[["methods_env"]] 18 | reference <- list(type_name = "animal", 19 | values_names = c("DOG", "CAT", "COW"), 20 | fields_names = NULL, 21 | values = list(DOG = enum_value("animal", temp, "DOG", 1L), 22 | CAT = enum_value("animal", temp, "CAT", 2L), 23 | COW = enum_value("animal", temp, "COW", 3L)), 24 | methods_env = temp) 25 | class(reference$values) <- c("list", "enum_list") 26 | class(reference) <- "enum_type" 27 | #length.enum_type <- base::length 28 | expect_equal(object, reference) 29 | }) 30 | 31 | test_that("enum_values are recoginized as enum_values", { 32 | object <- enum_value("animal", new.env(), "COW", 5L, list(voice = "mooo!", color = c("red", "white"))) 33 | expect_true(is.enum_value(object)) 34 | }) 35 | 36 | test_that("enum_types are recoginized as enum_types", { 37 | object <- enum_type("animal", 38 | c("DOG", "CAT", "COW")) 39 | expect_true(is.enum_type(object)) 40 | }) 41 | -------------------------------------------------------------------------------- /R/enum_type.R: -------------------------------------------------------------------------------- 1 | #' Enum type 2 | #' 3 | #' @description Creates new enum type. 4 | #' 5 | #' @param type_name Character vector of length 1. Name of the type. Type name will be referenced by this value 6 | #' @param value_names Character vector of positive length. Possible names of enum_values (instances) 7 | #' @param ... Optional other fields that are used during constructing enum_values 8 | #' 9 | #' @export 10 | 11 | enum_type <- function(type_name, values_names, ...) { 12 | fields <- as.list(match.call(expand.dots = FALSE)$`...`) 13 | fields <- lapply(fields, eval) 14 | n <- length(values_names) 15 | 16 | stopifnot(is.character(type_name)) 17 | stopifnot(length(type_name) == 1) 18 | stopifnot(all(unlist(lapply(fields, function(field) length(field) == n)))) 19 | stopifnot(is.character(values_names)) 20 | stopifnot(length(unique(values_names)) == n) 21 | 22 | if(length(fields) == 0) { 23 | fields_names <- NULL 24 | } else { 25 | fields_names <- names(fields) 26 | } 27 | 28 | methods_env <- new.env() 29 | methods_env$methods_universal <- list() 30 | methods_env$methods_switch <- list() 31 | 32 | new_type <- list(type_name = type_name, 33 | values_names = values_names, 34 | fields_names = fields_names, 35 | values = lapply(1L:n, 36 | function(index) enum_value(enum_type = type_name, 37 | methods_env = methods_env, 38 | value_name = values_names[index], 39 | index = index, 40 | lapply(fields, function(field) field[[index]]))), 41 | methods_env = methods_env) 42 | names(new_type$values) <- values_names 43 | new_type$values <- enum_list(new_type$values) 44 | class(new_type) <- "enum_type" 45 | new_type 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /vignettes/Introduction.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Introduction} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | This vignette will introduce you to basic functionalities of `enumeR` package. 11 | 12 | 13 | ```{r, include = FALSE} 14 | knitr::opts_chunk$set( 15 | collapse = TRUE, 16 | comment = "#>" 17 | ) 18 | ``` 19 | 20 | ```{r setup} 21 | library(enumeR) 22 | ``` 23 | 24 | First we create some `enum_type` object. It represents a class with finite number of possible values - similliar to enums from other languages like `C++` or `Java`. During construction of an object besides names of values you can specify values of own fields that will be kept inside values. For example: 25 | 26 | ```{r example} 27 | season_of_year <- enum_type("season_of_year", 28 | c("SPRING", "SUMMER", "AUTUMN", "WINTER"), 29 | min_temperature = c(-13, 7, -6, -20), 30 | max_temperature = c(20, 32, 18, 12)) 31 | 32 | print(season_of_year) 33 | ``` 34 | 35 | Now you can access values of this type: 36 | 37 | ```{r access} 38 | my_favourite_seasons <- season_of_year[c(1,4)] 39 | my_hated_seasons <- season_of_year[c("SUMMER","AUTUMN")] 40 | holiday_season <- season_of_year$SUMMER 41 | ``` 42 | 43 | ... but cannot modify it: 44 | ```{r modif, error=TRUE} 45 | season_of_year$SUMMER <- "something" 46 | ``` 47 | 48 | You can also choose a random subset: 49 | ```{r sample} 50 | sample_seasons <- sample_enum(season_of_year) 51 | ``` 52 | 53 | Objects have thier own classes, which can be checked: 54 | ```{r class} 55 | class(season_of_year) 56 | class(holiday_season) 57 | is.enum_type(season_of_year) 58 | is.enum_value(holiday_season) 59 | ``` 60 | 61 | You can add methods to `enum_type` which will be accessing its fields. You can access these fields using their names with dot before it. Thus it's not recommended to add fields which names begin with dot. 62 | ```{r methods} 63 | add_enum_methods(season_of_year, 64 | temperature_diff = function() { 65 | .max_temperature - .min_temperature 66 | }) 67 | 68 | get_enum_method(holiday_season, temperature_diff)() 69 | 70 | ``` 71 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /tests/testthat/test-accessing.R: -------------------------------------------------------------------------------- 1 | context("Accessing enum_values") 2 | 3 | simple_enum <- enum_type("color", 4 | c("RED", "GREEN", "BLUE"), 5 | hex_value = c("#FF0000", "#00FF00", "#0000FF")) 6 | 7 | red <- list(type_name = "color", 8 | methods_env = simple_enum[["methods_env"]], 9 | value_name = "RED", 10 | index = 1, 11 | hex_value = "#FF0000") 12 | class(red) <- "enum_value" 13 | 14 | green <- list(type_name = "color", 15 | methods_env = simple_enum[["methods_env"]], 16 | value_name = "GREEN", 17 | index = 2, 18 | hex_value = "#00FF00") 19 | class(green) <- "enum_value" 20 | 21 | test_that("enum_values are accessed properly with '$'", { 22 | expect_true(is.enum_value(simple_enum$RED)) 23 | expect_true(is.enum_value(simple_enum$GREEN)) 24 | expect_true(is.enum_value(simple_enum$BLUE)) 25 | expect_equal(simple_enum[["type_name"]], simple_enum$RED[["type_name"]]) 26 | expect_equal(simple_enum[["type_name"]], simple_enum$GREEN[["type_name"]]) 27 | expect_equal(simple_enum[["type_name"]], simple_enum$BLUE[["type_name"]]) 28 | expect_equal(simple_enum$RED, red) 29 | expect_equal(simple_enum$GREEN, green) 30 | }) 31 | 32 | test_that("it's not possible to modify enum_type with '$<-'", { 33 | expect_error(simple_enum$RED <- "anything", "You cannot modify enum_type values!" ) 34 | expect_error(simple_enum$GREEN <- "anything", "You cannot modify enum_type values!" ) 35 | expect_error(simple_enum$BLUE <- "anything", "You cannot modify enum_type values!" ) 36 | }) 37 | 38 | test_that("enum_values are subsetted properly with '['", { 39 | object <- simple_enum[1] 40 | expect_equal(object, list(RED = red)) 41 | object <- simple_enum[c(1,2,1)] 42 | reference <- list(RED = red, GREEN = green, RED = red) 43 | expect_equal(object, reference) 44 | object <- simple_enum[c("RED", "GREEN", "RED")] 45 | expect_equal(object, reference) 46 | }) 47 | 48 | test_that("it's not possible to modify enum_type with '[<-'", { 49 | expect_error(simple_enum[1] <- "anything", "You cannot modify enum_type values!" ) 50 | expect_error(simple_enum["GREEN"] <- "anything", "You cannot modify enum_type values!" ) 51 | expect_error(simple_enum[c(1,2,3,1)] <- "anything", "You cannot modify enum_type values!" ) 52 | expect_error(simple_enum[c("RED", "BLUE", "RED")] <- "anything", "You cannot modify enum_type values!" ) 53 | }) 54 | -------------------------------------------------------------------------------- /tests/testthat/test-methods.R: -------------------------------------------------------------------------------- 1 | context("Adding and accessing enum methods") 2 | 3 | color_enum <- enum_type("color_enum", 4 | c("QUEEN_BLUE", "DARK_PURPLE", "PINK_RASPBERRY"), 5 | red = c(67, 47, 156), 6 | green = c(124, 36, 13), 7 | blue = c(144, 58, 56)) 8 | 9 | qu <- color_enum$QUEEN_BLUE 10 | 11 | test_that("adding universal method with no parameters works", { 12 | add_enum_methods(color_enum, 13 | get_hex_color_w_index_name = function() { 14 | paste0(.value_name, 15 | " ", 16 | .index, 17 | " #", 18 | as.hexmode(.red), 19 | as.hexmode(.green), 20 | as.hexmode(.blue)) 21 | }) 22 | object <- color_enum[["methods_env"]]$methods_universal$get_hex_color_w_index_name(qu$value_name, 23 | qu$index, 24 | qu$red, 25 | qu$green, 26 | qu$blue) 27 | expect_equal(object, "QUEEN_BLUE 1 #437c90") 28 | }) 29 | 30 | test_that("adding universal method which does nothing with no parameters works", { 31 | add_enum_methods(color_enum, 32 | do_nothing = function() {NULL}) 33 | object <- color_enum[["methods_env"]]$methods_universal$do_nothing(qu$value_name, 34 | qu$index, 35 | qu$red, 36 | qu$green, 37 | qu$blue) 38 | expect_equal(object, NULL) 39 | }) 40 | 41 | test_that("adding universal method with some parameters works", { 42 | add_enum_methods(color_enum, 43 | return_multiplicity_of_index = function(multiplicity) { 44 | multiplicity * .index 45 | }) 46 | object <- color_enum[["methods_env"]]$methods_universal$return_multiplicity_of_index(12, 47 | qu$value_name, 48 | qu$index, 49 | qu$red, 50 | qu$green, 51 | qu$blue) 52 | expect_equal(object, 12) 53 | }) 54 | 55 | test_that("calling universal method with no parameters works", { 56 | object <- get_enum_method(qu, get_hex_color_w_index_name)() 57 | expect_equal(object, "QUEEN_BLUE 1 #437c90") 58 | }) 59 | 60 | test_that("calling universal method which does nothing with no parameters works", { 61 | object <- get_enum_method(qu, do_nothing)() 62 | expect_equal(object, NULL) 63 | }) 64 | 65 | test_that("calling universal method with some parameters works", { 66 | object <- get_enum_method(qu, return_multiplicity_of_index)(12) 67 | expect_equal(object, 12) 68 | }) 69 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $("#sidebar") 6 | .stick_in_parent({offset_top: 40}) 7 | .on('sticky_kit:bottom', function(e) { 8 | $(this).parent().css('position', 'static'); 9 | }) 10 | .on('sticky_kit:unbottom', function(e) { 11 | $(this).parent().css('position', 'relative'); 12 | }); 13 | 14 | $('body').scrollspy({ 15 | target: '#sidebar', 16 | offset: 60 17 | }); 18 | 19 | $('[data-toggle="tooltip"]').tooltip(); 20 | 21 | var cur_path = paths(location.pathname); 22 | var links = $("#navbar ul li a"); 23 | var max_length = -1; 24 | var pos = -1; 25 | for (var i = 0; i < links.length; i++) { 26 | if (links[i].getAttribute("href") === "#") 27 | continue; 28 | // Ignore external links 29 | if (links[i].host !== location.host) 30 | continue; 31 | 32 | var nav_path = paths(links[i].pathname); 33 | 34 | var length = prefix_length(nav_path, cur_path); 35 | if (length > max_length) { 36 | max_length = length; 37 | pos = i; 38 | } 39 | } 40 | 41 | // Add class to parent
  • , and enclosing
  • if in dropdown 42 | if (pos >= 0) { 43 | var menu_anchor = $(links[pos]); 44 | menu_anchor.parent().addClass("active"); 45 | menu_anchor.closest("li.dropdown").addClass("active"); 46 | } 47 | }); 48 | 49 | function paths(pathname) { 50 | var pieces = pathname.split("/"); 51 | pieces.shift(); // always starts with / 52 | 53 | var end = pieces[pieces.length - 1]; 54 | if (end === "index.html" || end === "") 55 | pieces.pop(); 56 | return(pieces); 57 | } 58 | 59 | // Returns -1 if not found 60 | function prefix_length(needle, haystack) { 61 | if (needle.length > haystack.length) 62 | return(-1); 63 | 64 | // Special case for length-0 haystack, since for loop won't run 65 | if (haystack.length === 0) { 66 | return(needle.length === 0 ? 0 : -1); 67 | } 68 | 69 | for (var i = 0; i < haystack.length; i++) { 70 | if (needle[i] != haystack[i]) 71 | return(i); 72 | } 73 | 74 | return(haystack.length); 75 | } 76 | 77 | /* Clipboard --------------------------*/ 78 | 79 | function changeTooltipMessage(element, msg) { 80 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 81 | element.setAttribute('data-original-title', msg); 82 | $(element).tooltip('show'); 83 | element.setAttribute('data-original-title', tooltipOriginalTitle); 84 | } 85 | 86 | if(ClipboardJS.isSupported()) { 87 | $(document).ready(function() { 88 | var copyButton = ""; 89 | 90 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 91 | 92 | // Insert copy buttons: 93 | $(copyButton).prependTo(".hasCopyButton"); 94 | 95 | // Initialize tooltips: 96 | $('.btn-copy-ex').tooltip({container: 'body'}); 97 | 98 | // Initialize clipboard: 99 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 100 | text: function(trigger) { 101 | return trigger.parentNode.textContent; 102 | } 103 | }); 104 | 105 | clipboardBtnCopies.on('success', function(e) { 106 | changeTooltipMessage(e.trigger, 'Copied!'); 107 | e.clearSelection(); 108 | }); 109 | 110 | clipboardBtnCopies.on('error', function() { 111 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 112 | }); 113 | }); 114 | } 115 | })(window.jQuery || window.$) 116 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 45 | 46 | 47 | 48 | 49 | 50 |
    51 |
    52 | 99 | 100 | 101 |
    102 | 103 |
    104 |
    105 | 108 | 109 |
    110 |

    All vignettes

    111 |

    112 | 113 | 116 |
    117 |
    118 |
    119 | 120 |
    121 | 124 | 125 |
    126 |

    Site built with pkgdown 1.3.0.

    127 |
    128 |
    129 |
    130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 45 | 46 | 47 | 48 | 49 | 50 |
    51 |
    52 | 99 | 100 | 101 |
    102 | 103 |
    104 |
    105 | 108 | 109 |
      110 |
    • 111 |

      Dominik Rafacz. Author, maintainer. 112 |

      113 |
    • 114 |
    • 115 |

      Mateusz Bąkała. Author. 116 |

      117 |
    • 118 |
    119 | 120 |
    121 | 122 |
    123 | 124 | 125 |
    126 | 129 | 130 |
    131 |

    Site built with pkgdown 1.3.0.

    132 |
    133 |
    134 |
    135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body > .container { 21 | display: flex; 22 | height: 100%; 23 | flex-direction: column; 24 | 25 | padding-top: 60px; 26 | } 27 | 28 | body > .container .row { 29 | flex: 1 0 auto; 30 | } 31 | 32 | footer { 33 | margin-top: 45px; 34 | padding: 35px 0 36px; 35 | border-top: 1px solid #e5e5e5; 36 | color: #666; 37 | display: flex; 38 | flex-shrink: 0; 39 | } 40 | footer p { 41 | margin-bottom: 0; 42 | } 43 | footer div { 44 | flex: 1; 45 | } 46 | footer .pkgdown { 47 | text-align: right; 48 | } 49 | footer p { 50 | margin-bottom: 0; 51 | } 52 | 53 | img.icon { 54 | float: right; 55 | } 56 | 57 | img { 58 | max-width: 100%; 59 | } 60 | 61 | /* Fix bug in bootstrap (only seen in firefox) */ 62 | summary { 63 | display: list-item; 64 | } 65 | 66 | /* Typographic tweaking ---------------------------------*/ 67 | 68 | .contents .page-header { 69 | margin-top: calc(-60px + 1em); 70 | } 71 | 72 | /* Section anchors ---------------------------------*/ 73 | 74 | a.anchor { 75 | margin-left: -30px; 76 | display:inline-block; 77 | width: 30px; 78 | height: 30px; 79 | visibility: hidden; 80 | 81 | background-image: url(./link.svg); 82 | background-repeat: no-repeat; 83 | background-size: 20px 20px; 84 | background-position: center center; 85 | } 86 | 87 | .hasAnchor:hover a.anchor { 88 | visibility: visible; 89 | } 90 | 91 | @media (max-width: 767px) { 92 | .hasAnchor:hover a.anchor { 93 | visibility: hidden; 94 | } 95 | } 96 | 97 | 98 | /* Fixes for fixed navbar --------------------------*/ 99 | 100 | .contents h1, .contents h2, .contents h3, .contents h4 { 101 | padding-top: 60px; 102 | margin-top: -40px; 103 | } 104 | 105 | /* Static header placement on mobile devices */ 106 | @media (max-width: 767px) { 107 | .navbar-fixed-top { 108 | position: absolute; 109 | } 110 | .navbar { 111 | padding: 0; 112 | } 113 | } 114 | 115 | 116 | /* Sidebar --------------------------*/ 117 | 118 | #sidebar { 119 | margin-top: 30px; 120 | } 121 | #sidebar h2 { 122 | font-size: 1.5em; 123 | margin-top: 1em; 124 | } 125 | 126 | #sidebar h2:first-child { 127 | margin-top: 0; 128 | } 129 | 130 | #sidebar .list-unstyled li { 131 | margin-bottom: 0.5em; 132 | } 133 | 134 | .orcid { 135 | height: 16px; 136 | vertical-align: middle; 137 | } 138 | 139 | /* Reference index & topics ----------------------------------------------- */ 140 | 141 | .ref-index th {font-weight: normal;} 142 | 143 | .ref-index td {vertical-align: top;} 144 | .ref-index .icon {width: 40px;} 145 | .ref-index .alias {width: 40%;} 146 | .ref-index-icons .alias {width: calc(40% - 40px);} 147 | .ref-index .title {width: 60%;} 148 | 149 | .ref-arguments th {text-align: right; padding-right: 10px;} 150 | .ref-arguments th, .ref-arguments td {vertical-align: top;} 151 | .ref-arguments .name {width: 20%;} 152 | .ref-arguments .desc {width: 80%;} 153 | 154 | /* Nice scrolling for wide elements --------------------------------------- */ 155 | 156 | table { 157 | display: block; 158 | overflow: auto; 159 | } 160 | 161 | /* Syntax highlighting ---------------------------------------------------- */ 162 | 163 | pre { 164 | word-wrap: normal; 165 | word-break: normal; 166 | border: 1px solid #eee; 167 | } 168 | 169 | pre, code { 170 | background-color: #f8f8f8; 171 | color: #333; 172 | } 173 | 174 | pre code { 175 | overflow: auto; 176 | word-wrap: normal; 177 | white-space: pre; 178 | } 179 | 180 | pre .img { 181 | margin: 5px 0; 182 | } 183 | 184 | pre .img img { 185 | background-color: #fff; 186 | display: block; 187 | height: auto; 188 | } 189 | 190 | code a, pre a { 191 | color: #375f84; 192 | } 193 | 194 | a.sourceLine:hover { 195 | text-decoration: none; 196 | } 197 | 198 | .fl {color: #1514b5;} 199 | .fu {color: #000000;} /* function */ 200 | .ch,.st {color: #036a07;} /* string */ 201 | .kw {color: #264D66;} /* keyword */ 202 | .co {color: #888888;} /* comment */ 203 | 204 | .message { color: black; font-weight: bolder;} 205 | .error { color: orange; font-weight: bolder;} 206 | .warning { color: #6A0366; font-weight: bolder;} 207 | 208 | /* Clipboard --------------------------*/ 209 | 210 | .hasCopyButton { 211 | position: relative; 212 | } 213 | 214 | .btn-copy-ex { 215 | position: absolute; 216 | right: 0; 217 | top: 0; 218 | visibility: hidden; 219 | } 220 | 221 | .hasCopyButton:hover button.btn-copy-ex { 222 | visibility: visible; 223 | } 224 | 225 | /* mark.js ----------------------------*/ 226 | 227 | mark { 228 | background-color: rgba(255, 255, 51, 0.5); 229 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 230 | padding: 1px; 231 | } 232 | 233 | /* vertical spacing after htmlwidgets */ 234 | .html-widget { 235 | margin-bottom: 10px; 236 | } 237 | -------------------------------------------------------------------------------- /docs/reference/is.enum_value.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TEMPORARRY DOCUMENTATION — is.enum_value • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    TEMPORARY DOCUMENTATION

    117 | 118 |
    119 | 120 |
    is.enum_value(object)
    121 | 122 | 123 |
    124 | 130 |
    131 | 132 |
    133 | 136 | 137 |
    138 |

    Site built with pkgdown 1.3.0.

    139 |
    140 |
    141 |
    142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/get_enum_values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TEMPORARRY DOCUMENTATION — get_enum_values • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    TEMPORARY DOCUMENTATION

    117 | 118 |
    119 | 120 |
    get_enum_values(enum_type)
    121 | 122 | 123 |
    124 | 130 |
    131 | 132 |
    133 | 136 | 137 |
    138 |

    Site built with pkgdown 1.3.0.

    139 |
    140 |
    141 |
    142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/add_enum_methods.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TEMPORARRY DOCUMENTATION — add_enum_methods • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    TEMPORARY DOCUMENTATION

    117 | 118 |
    119 | 120 |
    add_enum_methods(enum_type, ...)
    121 | 122 | 123 |
    124 | 130 |
    131 | 132 |
    133 | 136 | 137 |
    138 |

    Site built with pkgdown 1.3.0.

    139 |
    140 |
    141 |
    142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/get_enum_method.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TEMPORARRY DOCUMENTATION — get_enum_method • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    TEMPORARY DOCUMENTATION

    117 | 118 |
    119 | 120 |
    get_enum_method(enum_value, method)
    121 | 122 | 123 |
    124 | 130 |
    131 | 132 |
    133 | 136 | 137 |
    138 |

    Site built with pkgdown 1.3.0.

    139 |
    140 |
    141 |
    142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/methodize.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | @title TEMPORARRY DOCUMENTATION — methodize • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    @description TEMPORARY DOCUMENTATION

    117 | 118 |
    119 | 120 |
    methodize(enum_type, method)
    121 | 122 | 123 |
    124 | 130 |
    131 | 132 |
    133 | 136 | 137 |
    138 |

    Site built with pkgdown 1.3.0.

    139 |
    140 |
    141 |
    142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/apply_enum_method.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TEMPORARRY DOCUMENTATION — apply_enum_method • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    TEMPORARY DOCUMENTATION

    117 | 118 |
    119 | 120 |
    apply_enum_method(enum_value, method, ...)
    121 | 122 | 123 |
    124 | 130 |
    131 | 132 |
    133 | 136 | 137 |
    138 |

    Site built with pkgdown 1.3.0.

    139 |
    140 |
    141 |
    142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /docs/reference/print.enum_value.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | TEMPORARRY DOCUMENTATION — print.enum_value • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    TEMPORARY DOCUMENTATION

    117 | 118 |
    119 | 120 |
    # S3 method for enum_value
    121 | print(enum_value)
    122 | 123 | 124 |
    125 | 131 |
    132 | 133 |
    134 | 137 | 138 |
    139 |

    Site built with pkgdown 1.3.0.

    140 |
    141 |
    142 |
    143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/reference/cash-.enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get subset of values of enum_type — $.enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    placeholder

    117 | 118 |
    119 | 120 |
    # S3 method for enum_type
    121 | $(enum_type, value)
    122 | 123 |

    Arguments

    124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
    enum_type

    enum_type

    index

    index

    135 | 136 | 137 |
    138 | 145 |
    146 | 147 |
    148 | 151 | 152 |
    153 |

    Site built with pkgdown 1.3.0.

    154 |
    155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /docs/reference/sub-.enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get subset of values of enum_type — [.enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    placeholder

    117 | 118 |
    119 | 120 |
    # S3 method for enum_type
    121 | [(enum_type, index)
    122 | 123 |

    Arguments

    124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
    enum_type

    enum_type

    index

    index

    135 | 136 | 137 |
    138 | 145 |
    146 | 147 |
    148 | 151 | 152 |
    153 |

    Site built with pkgdown 1.3.0.

    154 |
    155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /docs/reference/subset-.enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get subset of values of enum_type — [<-.enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    placeholder

    117 | 118 |
    119 | 120 |
    # S3 method for enum_type
    121 | [(enum_type, index) <- value
    122 | 123 |

    Arguments

    124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
    enum_type

    enum_type

    index

    index

    135 | 136 | 137 |
    138 | 145 |
    146 | 147 |
    148 | 151 | 152 |
    153 |

    Site built with pkgdown 1.3.0.

    154 |
    155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /docs/reference/cash-set-.enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get subset of values of enum_type — $<-.enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    placeholder

    117 | 118 |
    119 | 120 |
    # S3 method for enum_type
    121 | $(enum_type, index) <- value
    122 | 123 |

    Arguments

    124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
    enum_type

    enum_type

    index

    index

    135 | 136 | 137 |
    138 | 145 |
    146 | 147 |
    148 | 151 | 152 |
    153 |

    Site built with pkgdown 1.3.0.

    154 |
    155 |
    156 |
    157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /docs/reference/print.enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Print enum_type — print.enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    Pretty prints enum_type object. Overloads default print.

    117 | 118 |
    119 | 120 |
    # S3 method for enum_type
    121 | print(enum_type)
    122 | 123 |

    Arguments

    124 | 125 | 126 | 127 | 128 | 129 | 130 |
    enum_type

    Object of class enum_type

    131 | 132 | 133 |
    134 | 141 |
    142 | 143 |
    144 | 147 | 148 |
    149 |

    Site built with pkgdown 1.3.0.

    150 |
    151 |
    152 |
    153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /docs/reference/as.enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Coerce to an enum type — as.enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    Functions to check if an object is an enum type, or coerce it if possible.

    117 | 118 |
    119 | 120 |
    as.enum_type(x)
    121 | 122 |

    Arguments

    123 | 124 | 125 | 126 | 127 | 128 | 129 |
    x

    any R object

    130 | 131 |

    Value

    132 | 133 |

    Object of class enum_type

    134 | 135 | 136 |
    137 | 146 |
    147 | 148 |
    149 | 152 | 153 |
    154 |

    Site built with pkgdown 1.3.0.

    155 |
    156 |
    157 |
    158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Enum types support for R • enumeR 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 |
    22 |
    67 | 68 | 69 | 70 |
    71 |
    72 | 73 |
    74 | 76 |

    This package provides enum_type and enum classes, which allows to create and instantinize enumerable types in R

    77 |

    It is in it’s early development and authors don’t grat any assurance that function names, parameters or functionalities won’t change in future.

    78 |
    79 |
    80 |

    81 | Installation

    82 |

    To install this package you need to use devtools library, which can be installed with:

    83 |
    install.packages("devtools")
    84 |

    If you have already installed devtools, you need to run following code to install this package:

    85 |
    devtools::install_github("DominikRafacz/enumeR")
    86 |
    87 | 88 |
    89 | 90 | 106 |
    107 | 108 |
    111 | 112 |
    113 |

    Site built with pkgdown 1.3.0.

    114 |
    115 |
    116 |
    117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /docs/reference/get_enum_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Get Enum Index — get_enum_index • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    Extracts `index` attribute value of passed `enum_value`.

    117 | 118 |
    119 | 120 |
    get_enum_index(enum_value)
    121 | 122 |

    Arguments

    123 | 124 | 125 | 126 | 127 | 128 | 129 |
    enum_value

    object of class `enum_value` or list of such objects with the same `enum_type`

    130 | 131 |

    Value

    132 | 133 |

    integer index of `enum_value` or named vector of integers coresponding to values in list

    134 | 135 | 136 |
    137 | 146 |
    147 | 148 |
    149 | 152 | 153 |
    154 |

    Site built with pkgdown 1.3.0.

    155 |
    156 |
    157 |
    158 | 159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /docs/reference/enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Enum type — enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    Creates new enum type.

    117 | 118 |
    119 | 120 |
    enum_type(type_name, values_names, ...)
    121 | 122 |

    Arguments

    123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 |
    type_name

    Character vector of length 1. Name of the type. Type name will be referenced by this value

    ...

    Optional other fields that are used during constructing enum_values

    value_names

    Character vector of positive length. Possible names of enum_values (instances)

    138 | 139 | 140 |
    141 | 148 |
    149 | 150 |
    151 | 154 | 155 |
    156 |

    Site built with pkgdown 1.3.0.

    157 |
    158 |
    159 |
    160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /docs/reference/is.enum_type.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Test if the object is an enum type — is.enum_type • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 52 | 53 | 54 | 55 | 56 | 57 |
    58 |
    59 | 106 | 107 | 108 |
    109 | 110 |
    111 |
    112 | 117 | 118 |
    119 | 120 |

    This function checks class of passed object. If vector of classes contains 121 | "enum_type", then checks if all necessary fields are not null, namely 122 | type_name and values, and whether type_name is a singular 123 | character vector. Next, checks if fields_names is a character vector or null. 124 | Lastly, all values need to be unique and proper enum_value objects.

    125 | 126 |
    127 | 128 |
    is.enum_type(object)
    129 | 130 |

    Value

    131 | 132 |

    TRUE if the object passed all tests described above, FALSE otherwise.

    133 | 134 | 135 |
    136 | 144 |
    145 | 146 |
    147 | 150 | 151 |
    152 |

    Site built with pkgdown 1.3.0.

    153 |
    154 |
    155 |
    156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /docs/reference/sample_enum.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Sample n values from an enum type — sample_enum • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 |
    54 |
    55 | 102 | 103 | 104 |
    105 | 106 |
    107 |
    108 | 113 | 114 |
    115 | 116 |

    This is a wrapper around [sample()] to make selecting random enum values easier.

    117 | 118 |
    119 | 120 |
    sample_enum(enum_type, size, replace = FALSE, weight = NULL)
    121 | 122 |

    Arguments

    123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 141 | 142 |
    enum_type

    Object that passes [is.enum_type()] check.

    size

    A non-negative integer giving number of items to choose.

    replace

    Should sampling be with replacement?

    weight

    Sampling weights. This must evaluate to a vector of non-negative numbers the same 140 | length as the input. Weights are automatically standardised to sum to 1.

    143 | 144 |

    Value

    145 | 146 |

    A list of enum values of length size drawn from enum_type's values.

    147 | 148 | 149 |
    150 | 159 |
    160 | 161 |
    162 | 165 | 166 |
    167 |

    Site built with pkgdown 1.3.0.

    168 |
    169 |
    170 |
    171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Function reference • enumeR 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 45 | 46 | 47 | 48 | 49 | 50 |
    51 |
    52 | 99 | 100 | 101 |
    102 | 103 |
    104 |
    105 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 123 | 124 | 125 | 126 | 129 | 130 | 131 | 132 | 135 | 136 | 137 | 138 | 141 | 142 | 143 | 144 | 147 | 148 | 149 | 150 | 153 | 154 | 155 | 156 | 159 | 160 | 161 | 162 | 165 | 166 | 167 | 168 | 171 | 172 | 173 | 174 | 177 | 178 | 179 | 180 | 183 | 184 | 185 | 186 | 189 | 190 | 191 | 192 | 195 | 196 | 197 | 198 | 201 | 202 | 203 | 204 | 207 | 208 | 209 | 210 | 213 | 214 | 215 | 216 | 219 | 220 | 221 | 222 | 225 | 226 | 227 | 228 |
    120 |

    All functions

    121 |

    122 |
    127 |

    add_enum_methods()

    128 |

    TEMPORARRY DOCUMENTATION

    133 |

    apply_enum_method()

    134 |

    TEMPORARRY DOCUMENTATION

    139 |

    as.enum_type()

    140 |

    Coerce to an enum type

    145 |

    `$`(<enum_type>)

    146 |

    Get subset of values of enum_type

    151 |

    `$<-`(<enum_type>)

    152 |

    Get subset of values of enum_type

    157 |

    enum_type()

    158 |

    Enum type

    163 |

    get_enum_index()

    164 |

    Get Enum Index

    169 |

    get_enum_method()

    170 |

    TEMPORARRY DOCUMENTATION

    175 |

    get_enum_values()

    176 |

    TEMPORARRY DOCUMENTATION

    181 |

    is.enum_type()

    182 |

    Test if the object is an enum type

    187 |

    is.enum_value()

    188 |

    TEMPORARRY DOCUMENTATION

    193 |

    methodize()

    194 |

    @title TEMPORARRY DOCUMENTATION

    199 |

    print(<enum_type>)

    200 |

    Print enum_type

    205 |

    print(<enum_value>)

    206 |

    TEMPORARRY DOCUMENTATION

    211 |

    sample_enum()

    212 |

    Sample n values from an enum type

    217 |

    `[`(<enum_type>)

    218 |

    Get subset of values of enum_type

    223 |

    `[<-`(<enum_type>)

    224 |

    Get subset of values of enum_type

    229 |
    230 | 231 | 237 |
    238 | 239 |
    240 | 243 | 244 |
    245 |

    Site built with pkgdown 1.3.0.

    246 |
    247 |
    248 |
    249 | 250 | 251 | 252 | 253 | 254 | 255 | -------------------------------------------------------------------------------- /docs/docsearch.css: -------------------------------------------------------------------------------- 1 | /* Docsearch -------------------------------------------------------------- */ 2 | /* 3 | Source: https://github.com/algolia/docsearch/ 4 | License: MIT 5 | */ 6 | 7 | .algolia-autocomplete { 8 | display: block; 9 | -webkit-box-flex: 1; 10 | -ms-flex: 1; 11 | flex: 1 12 | } 13 | 14 | .algolia-autocomplete .ds-dropdown-menu { 15 | width: 100%; 16 | min-width: none; 17 | max-width: none; 18 | padding: .75rem 0; 19 | background-color: #fff; 20 | background-clip: padding-box; 21 | border: 1px solid rgba(0, 0, 0, .1); 22 | box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); 23 | } 24 | 25 | @media (min-width:768px) { 26 | .algolia-autocomplete .ds-dropdown-menu { 27 | width: 175% 28 | } 29 | } 30 | 31 | .algolia-autocomplete .ds-dropdown-menu::before { 32 | display: none 33 | } 34 | 35 | .algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { 36 | padding: 0; 37 | background-color: rgb(255,255,255); 38 | border: 0; 39 | max-height: 80vh; 40 | } 41 | 42 | .algolia-autocomplete .ds-dropdown-menu .ds-suggestions { 43 | margin-top: 0 44 | } 45 | 46 | .algolia-autocomplete .algolia-docsearch-suggestion { 47 | padding: 0; 48 | overflow: visible 49 | } 50 | 51 | .algolia-autocomplete .algolia-docsearch-suggestion--category-header { 52 | padding: .125rem 1rem; 53 | margin-top: 0; 54 | font-size: 1.3em; 55 | font-weight: 500; 56 | color: #00008B; 57 | border-bottom: 0 58 | } 59 | 60 | .algolia-autocomplete .algolia-docsearch-suggestion--wrapper { 61 | float: none; 62 | padding-top: 0 63 | } 64 | 65 | .algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { 66 | float: none; 67 | width: auto; 68 | padding: 0; 69 | text-align: left 70 | } 71 | 72 | .algolia-autocomplete .algolia-docsearch-suggestion--content { 73 | float: none; 74 | width: auto; 75 | padding: 0 76 | } 77 | 78 | .algolia-autocomplete .algolia-docsearch-suggestion--content::before { 79 | display: none 80 | } 81 | 82 | .algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { 83 | padding-top: .75rem; 84 | margin-top: .75rem; 85 | border-top: 1px solid rgba(0, 0, 0, .1) 86 | } 87 | 88 | .algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { 89 | display: block; 90 | padding: .1rem 1rem; 91 | margin-bottom: 0.1; 92 | font-size: 1.0em; 93 | font-weight: 400 94 | /* display: none */ 95 | } 96 | 97 | .algolia-autocomplete .algolia-docsearch-suggestion--title { 98 | display: block; 99 | padding: .25rem 1rem; 100 | margin-bottom: 0; 101 | font-size: 0.9em; 102 | font-weight: 400 103 | } 104 | 105 | .algolia-autocomplete .algolia-docsearch-suggestion--text { 106 | padding: 0 1rem .5rem; 107 | margin-top: -.25rem; 108 | font-size: 0.8em; 109 | font-weight: 400; 110 | line-height: 1.25 111 | } 112 | 113 | .algolia-autocomplete .algolia-docsearch-footer { 114 | width: 110px; 115 | height: 20px; 116 | z-index: 3; 117 | margin-top: 10.66667px; 118 | float: right; 119 | font-size: 0; 120 | line-height: 0; 121 | } 122 | 123 | .algolia-autocomplete .algolia-docsearch-footer--logo { 124 | background-image: url("data:image/svg+xml;utf8,"); 125 | background-repeat: no-repeat; 126 | background-position: 50%; 127 | background-size: 100%; 128 | overflow: hidden; 129 | text-indent: -9000px; 130 | width: 100%; 131 | height: 100%; 132 | display: block; 133 | transform: translate(-8px); 134 | } 135 | 136 | .algolia-autocomplete .algolia-docsearch-suggestion--highlight { 137 | color: #FF8C00; 138 | background: rgba(232, 189, 54, 0.1) 139 | } 140 | 141 | 142 | .algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { 143 | box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) 144 | } 145 | 146 | .algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { 147 | background-color: rgba(192, 192, 192, .15) 148 | } 149 | -------------------------------------------------------------------------------- /docs/articles/Introduction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Introduction • enumeR 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 |
    22 |
    67 | 68 | 69 | 70 |
    71 |
    72 | 80 | 81 | 82 | 83 |

    This vignette will introduce you to basic functionalities of enumeR package.

    84 |
    library(enumeR)
    85 |

    First we create some enum_type object. It represents a class with finite number of possible values - similliar to enums from other languages like C++ or Java. During construction of an object besides names of values you can specify values of own fields that will be kept inside values. For example:

    86 |
    season_of_year <- enum_type("season_of_year", 
     87 |                             c("SPRING", "SUMMER", "AUTUMN", "WINTER"),
     88 |                             min_temperature = c(-13, 7, -6, -20),
     89 |                             max_temperature = c(20, 32, 18, 12))
     90 | 
     91 | print(season_of_year)
     92 | #> Enum type:  season_of_year 
     93 | #> 
     94 | #> Values:
     95 | #> 1  :  SPRING 
     96 | #> 2  :  SUMMER 
     97 | #> 3  :  AUTUMN 
     98 | #> 4  :  WINTER
     99 | #> $SPRING
    100 | #> NULL
    101 | #> 
    102 | #> $SUMMER
    103 | #> NULL
    104 | #> 
    105 | #> $AUTUMN
    106 | #> NULL
    107 | #> 
    108 | #> $WINTER
    109 | #> NULL
    110 |

    Now you can access values of this type:

    111 | 114 |

    … but cannot modify it:

    115 | 117 |

    You can also choose a random subset:

    118 | 119 |

    Objects have thier own classes, which can be checked:

    120 |
    class(season_of_year)
    121 | #> [1] "enum_type"
    122 | class(holiday_season)
    123 | #> [1] "enum_value"
    124 | is.enum_type(season_of_year)
    125 | #> [1] TRUE
    126 | is.enum_value(holiday_season)
    127 | #> [1] TRUE
    128 |

    You can add methods to enum_type which will be accessing its fields. You can access these fields using their names with dot before it. Thus it’s not recommended to add fields which names begin with dot.

    129 |
    add_enum_methods(season_of_year,
    130 |                  temperature_diff = function() {
    131 |                    .max_temperature - .min_temperature
    132 |                  })
    133 | 
    134 | get_enum_method(holiday_season, temperature_diff)()
    135 | #> [1] 25
    136 |
    137 | 138 | 140 | 141 |
    142 | 143 | 144 | 152 |
    153 | 154 | 155 | 156 | 157 | 158 | --------------------------------------------------------------------------------