postlogic/0000755000175100001440000000000013576367056012315 5ustar hornikuserspostlogic/NAMESPACE0000644000175100001440000000017513373321470013520 0ustar hornikusers# Generated by roxygen2: do not edit by hand export("%if%") export("%otherwise%") export("%then%") export("%unless%") postlogic/README.md0000644000175100001440000000377013373066346013574 0ustar hornikusers postlogic ========= [![Travis build status](https://travis-ci.org/RDocTaskForce/postlogic.svg?branch=master)](https://travis-ci.org/RDocTaskForce/postlogic) [![Coverage status](https://codecov.io/gh/RDocTaskForce/postlogic/branch/master/graph/badge.svg)](https://codecov.io/github/RDocTaskForce/postlogic?branch=master) The goal of postlogic is to allow natural flowing logic statements. Installation ------------ You can install the released version of postlogic from [CRAN](https://CRAN.R-project.org) with: ``` r install.packages("postlogic") ``` If/Otherwise ------------ The if/otherwise instruction allows for simple logic to follow a statement to make it conditional. The `%if%` can be used alone to make an action conditional. ``` r verbose <- TRUE message("Hello there") %if% verbose #> Hello there ``` When combined with the `%otherwise%` statement it allows for an alternate. ``` r mood <- "calm" message("How dare you!") %if% (mood == 'angry') %otherwise% message("Everything is fine.") #> Everything is fine. mood <- 'angry' message("How dare you!") %if% (mood == 'angry') %otherwise% message("Everything is fine.") #> How dare you! ``` Unless/Then ----------- The `%unless%` operator is essentially the negation of `%if%`. So when a statement is postfixed by an `%unless%` statement it will happen unless the proposition returns `TRUE`. The alternating operator for `%unless%` is `%then%`. ``` r mood <- 'calm' message("Everything is fine.") %unless% (mood == 'angry') %then% message("How dare you!") #> Everything is fine. ``` This example is the same effect as the statements in the previous example. Documentation ------------- The `postlogic` package is developed by the R Documentation Task Force, an [R Consortium](https://www.r-consortium.org) [Infrastructure Steering Committee working group](https://www.r-consortium.org/projects/isc-working-groups). postlogic/man/0000755000175100001440000000000013372351572013056 5ustar hornikuserspostlogic/man/if-otherwise.Rd0000644000175100001440000000206013373323505015744 0ustar hornikusers\name{if-otherwise} \alias{if-otherwise} \alias{\%if\%} \alias{\%otherwise\%} \title{Postfix if-otherwise logic} \usage{ prior \%if\% proposition prior \%if\% proposition \%otherwise\% alternate } \arguments{ \item{prior}{The value to be returned if proposition evaluates to TRUE.} \item{proposition}{The logical statement to evaluate} \item{alternate}{The value to be returned if proposition evaluates to FALSE.} \item{prior \%if\% proposition}{An \code{\%if\%} statement.} } \description{ This construction allows logical statements to be placed after the value to be returned. Take note that the `%if%` and `%otherwise%` operators follow the same order of operations as other custom infix operators and so care should be taken that the effect is as desired. } \examples{ x <- 1 x <- (x+1) \%if\% is.numeric(x) \%otherwise\% "Hmm this isn't right O.o" x # 2 x <- 1i x <- (x+1) \%if\% is.numeric(x) \%otherwise\% "Hmm this isn't right O.o" x # Hmm this isn't right } \seealso{ Other postlogic: \code{\link{unless-then}} } \concept{postlogic} postlogic/man/unless-then.Rd0000644000175100001440000000212013373363340015602 0ustar hornikusers\name{unless-then} \alias{unless-then} \alias{\%unless\%} \alias{\%then\%} \title{Infix unless-then logic} \usage{ prior \%unless\% proposition prior \%unless\% proposition \%then\% alternate } \arguments{ \item{prior}{Value to be returned unless proposition returns FALSE.} \item{proposition}{The logical statement to condition on.} \item{alternate}{When proposition returns true and the %then% is provided the alternate value is returned.} \item{prior \%unless\% proposition}{An \code{\%if\%} statement.} } \description{ These give logic that can be used as a qualifying statement that occurs after the value statement. Take note that the `%unless%` and `%then%` operators follow the same order of operations as other custom infix operators and so care should be taken that the effect is as desired. } \examples{ x <- 4 x <- sqrt(x) \%unless\% is.complex(x) \%then\% "This is too hard :(" x # 2 x <- 4i x <- sqrt(x) \%unless\% is.complex(x) \%then\% "This is too hard :(" x # This is too hard :( } \seealso{ Other postlogic: \code{\link{if-otherwise}} } \concept{postlogic} postlogic/DESCRIPTION0000644000175100001440000000152013576367056014021 0ustar hornikusersPackage: postlogic Type: Package Title: Infix and Postfix Logic Operators Version: 0.1.0.1 Authors@R: person("Andrew", "Redd", role = c("aut", "cre") , email = "Andrew.Redd@hsc.utah.edu" , comment = c(ORCID = "https://orcid.org/0000-0002-6149-2438") ) Maintainer: Andrew Redd Description: Provides adds postfix and infix logic operators for if, then, unless, and otherwise. Language: en-US License: GPL-2 Encoding: UTF-8 LazyData: true Suggests: testthat, covr URL: https://github.com/RDocTaskForce/postlogic BugReports: https://github.com/RDocTaskForce/postlogic/issues NeedsCompilation: no Packaged: 2019-12-18 09:12:45 UTC; hornik Author: Andrew Redd [aut, cre] () Repository: CRAN Date/Publication: 2019-12-18 09:15:26 UTC postlogic/tests/0000755000175100001440000000000013372350675013450 5ustar hornikuserspostlogic/tests/testthat/0000755000175100001440000000000013576367056015317 5ustar hornikuserspostlogic/tests/testthat/test-unless-then.R0000644000175100001440000000254013373063711020647 0ustar hornikusers#! This file was automatically produced by the testextra package. #! Changes will be overwritten. context('tests extracted from file `unless-then.R`') #line 46 "R/unless-then.R" test_that('unless-then logic', {#@testing unless-then logic if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it is supposed to be evaluated') %unless% FALSE expect_equal(val, 'it is supposed to be evaluated') expect_identical(val, x) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %unless% TRUE expect_null(val) expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %unless% TRUE %then% "should get this" expect_equal(val, "should get this") expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it is supposed to be evaluated') %unless% FALSE %then% "should not get this" expect_equal(val, 'it is supposed to be evaluated') expect_true(exists('x', inherits=FALSE)) expect_equal(x, 'it is supposed to be evaluated') if (exists('x', inherits=FALSE)) rm(list='x') expect_error( 'this' %if% 'wont' %then% 'work' , "Infix opperator '%then%' can only be used following an '%unless%' infix." ) }) postlogic/tests/testthat/test-if-otherwise.R0000644000175100001440000000223613373063711021011 0ustar hornikusers#! This file was automatically produced by the testextra package. #! Changes will be overwritten. context('tests extracted from file `if-otherwise.R`') #line 46 "R/if-otherwise.R" test_that('if-otherwise logic', {#@testing if-otherwise logic if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %if% FALSE expect_null(val) expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %if% FALSE %otherwise% "should get this" expect_equal(val, "should get this") expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it is supposed to be evaluated') %if% TRUE %otherwise% "should not get this" expect_equal(val, 'it is supposed to be evaluated') expect_true(exists('x', inherits=FALSE)) expect_equal(x, 'it is supposed to be evaluated') if (exists('x', inherits=FALSE)) rm(list='x') expect_error( 'this' %unless% 'wont' %otherwise% 'work' , "Infix opperator '%otherwise%' can only be used following an '%if%' infix." ) }) postlogic/tests/testthat.R0000644000175100001440000000010213372350675015424 0ustar hornikuserslibrary(testthat) library(postlogic) test_check("postlogic") postlogic/R/0000755000175100001440000000000013372350452012500 5ustar hornikuserspostlogic/R/if-otherwise.R0000644000175100001440000000322313373324751015234 0ustar hornikusers `%if%` <- function( prior, proposition ){ if (proposition) return(prior) } `%otherwise%` <- function(`%if% prior proposition`, alternate){ clause.call <- substitute(`%if% prior proposition`) if (clause.call[[1]] != '%if%') stop("Infix opperator '%otherwise%' can only be used following an '%if%' infix.") value <- clause.call[[2]] predicate <- clause.call[[3]] predicate.value <- eval.parent(predicate) if (predicate.value) eval.parent(value) else alternate } if(FALSE){#@testing if-otherwise logic if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %if% FALSE expect_null(val) expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %if% FALSE %otherwise% "should get this" expect_equal(val, "should get this") expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it is supposed to be evaluated') %if% TRUE %otherwise% "should not get this" expect_equal(val, 'it is supposed to be evaluated') expect_true(exists('x', inherits=FALSE)) expect_equal(x, 'it is supposed to be evaluated') if (exists('x', inherits=FALSE)) rm(list='x') expect_error( 'this' %unless% 'wont' %otherwise% 'work' , "Infix opperator '%otherwise%' can only be used following an '%if%' infix." ) } if(FALSE){#@example x <- 1 x <- (x+1) %if% is.numeric(x) %otherwise% "Hmm this isn't right O.o" x # 2 x <- 1i x <- (x+1) %if% is.numeric(x) %otherwise% "Hmm this isn't right O.o" x # Hmm this isn't right } postlogic/R/unless-then.R0000644000175100001440000000356713373324764015113 0ustar hornikusers `%unless%` <- function( prior, proposition ){ if (!proposition) return(prior) } `%then%` <- function( `%unless% prior proposition`, alternate){ clause.call <- substitute(`%unless% prior proposition`) if (clause.call[[1]] != '%unless%') stop("Infix opperator '%then%' can only be used following an '%unless%' infix.") value <- clause.call[[2]] predicate <- clause.call[[3]] predicate.value <- eval(predicate, envir = parent.frame()) if (!predicate.value) eval(value, envir = parent.frame()) else alternate } if(FALSE){#@testing unless-then logic if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it is supposed to be evaluated') %unless% FALSE expect_equal(val, 'it is supposed to be evaluated') expect_identical(val, x) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %unless% TRUE expect_null(val) expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it still evaluated') %unless% TRUE %then% "should get this" expect_equal(val, "should get this") expect_false(exists('x', inherits=FALSE)) if (exists('x', inherits=FALSE)) rm(list='x') val <- (x <- 'it is supposed to be evaluated') %unless% FALSE %then% "should not get this" expect_equal(val, 'it is supposed to be evaluated') expect_true(exists('x', inherits=FALSE)) expect_equal(x, 'it is supposed to be evaluated') if (exists('x', inherits=FALSE)) rm(list='x') expect_error( 'this' %if% 'wont' %then% 'work' , "Infix opperator '%then%' can only be used following an '%unless%' infix." ) } if(FALSE){#@example x <- 4 x <- sqrt(x) %unless% is.complex(x) %then% "This is too hard :(" x # 2 x <- 4i x <- sqrt(x) %unless% is.complex(x) %then% "This is too hard :(" x # This is too hard :( } postlogic/MD50000644000175100001440000000110213576367056012617 0ustar hornikusersafffacfe178a204b816ce21e3d8af907 *DESCRIPTION d51b5edb8e8f5fd4fbf7b347c6646f8f *NAMESPACE 716a239dfd02ad80a5cbc63a243f7ccd *R/if-otherwise.R 055edf5d34ef4d275800512ec0599259 *R/unless-then.R 12fedbfb7e89153d7908c02c65c450b5 *README.md 5fa94bd5078f0b20d4c4cc4290fe9374 *inst/WORDLIST 9583f652fcfce92064a1318cec1f1c1d *man/if-otherwise.Rd 24927669136b71ebecb2286275e2cc95 *man/unless-then.Rd b6ae89addb28a7b432bcd3e22af53148 *tests/testthat.R c90fdff2f8163cdc02d169472708b7f2 *tests/testthat/test-if-otherwise.R f72b73d39f9058c21bb71aa81e5bc680 *tests/testthat/test-unless-then.R postlogic/inst/0000755000175100001440000000000013373363435013262 5ustar hornikuserspostlogic/inst/WORDLIST0000644000175100001440000000002213373363435014446 0ustar hornikuserspostfix Postfix