Skip to content

Commit

Permalink
Merge pull request #4 from gogonzo/fix_cran
Browse files Browse the repository at this point in the history
fix cran comments
  • Loading branch information
gogonzo authored Dec 13, 2021
2 parents db72ef2 + e9feef2 commit 199bfde
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 16 deletions.
16 changes: 11 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ Package: ox
Type: Package
Title: Shorthand if-Else
Version: 0.1.0
Authors@R: person("Dawid", "Kałędkowski",
email = "[email protected]",
comment = c(ORCID = "0000-0001-9533-457X"),
role = c("aut", "cre"))
Authors@R:
c(person(given = "Dawid",
family = "Kałędkowski",
email = "[email protected]",
comment = c(ORCID = "0000-0001-9533-457X"),
role = c("aut", "cre")),
person(given = "Paweł",
family = "Rucki",
email = "[email protected]",
role = "aut"))
Maintainer: Dawid Kałędkowski <[email protected]>
Description: Short hand if-else function to easily switch the values depending
on a conditions.
on a logical condition.
License: GPL (>= 2)
BugReports: https://github.com/gogonzo/ox/issues
Encoding: UTF-8
Expand Down
10 changes: 6 additions & 4 deletions R/OX2.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@
#' `OX(Negate(.f), ..., .then, .else)`.
#'
#' @examples
#' # switch values of vector by
#' # switch values of the vector when condition is true
#' OX(is.na, c(1, NA, 3), .else = c(2, 2, 2))
#' @return object (`atomic`, `list`) - same object as `.then` with values
#' replaced by `.else`.
#' @return `atomic` or `list`. Returned object is a `.then` object with elements
#' replaced by `.else` depending on a result of the logical condition.
#' @export
OX <- function(.f, ..., .then = list(...)[[1]], .else = rev(list(...))[[1]]) { # nolint
OX_default(.f = .f, ..., .then = .then, .else = .else, .invert = TRUE)
}

#' @rdname vectorized-ox
#' @examples
#'
#' # use OX to invert negate the condition
#' XO(is.na, c(1, NA, 3), .else = c(2, 2, 2))
#' @export
XO <- function(.f, ..., .then = list(...)[[1]], .else = rev(list(...))[[1]]) { # nolint
Expand All @@ -58,7 +60,7 @@ XO <- function(.f, ..., .then = list(...)[[1]], .else = rev(list(...))[[1]]) { #
#' Utility function to run OX
#'
#' @inheritParams vectorized-ox
#' @param .invert (`logical(1)`)
#' @param .invert (`logical(1)`) whether to invert the indices
#' @keywords internal
OX_default <- function(.f, ..., .then = list(...)[[1]], .else = rev(list(...))[[1]], .invert = FALSE) { # nolint
check_thenelse_OX(.then, .else)
Expand Down
2 changes: 2 additions & 0 deletions R/ox.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#' To invert the switch one can use `xo` which is equivalent of
#' `ox(Negate(.f), ..., .then, .else)`.
#'
#' @return object identical to `.then` or `.else` depending on the condition
#' result.
#' @examples
#' # if (is.null(NULL)) NULL else 1
#' ox(NULL, .f = is.null, .else = 1)
Expand Down
4 changes: 3 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ validate_f_out.logical <- function(idx, len) {
#' Checks if .then and .else are fine. If they have supported classes and
#' if their length is the same.
#' @inheritParams vectorized-ox
#' @return `NULL` invisible.
#' @keywords internal
check_thenelse_OX <- function(.then, .else) { # nolint
if (!inherits(.then, c("list", "logical", "integer", "numeric", "character", "factor"))) {
Expand All @@ -86,6 +87,7 @@ check_thenelse_OX <- function(.then, .else) { # nolint
"\n Can't replace values of `.then` by values of `.else`",
call. = FALSE)
}
invisible(NULL)
}

#' Indices inversion
Expand All @@ -94,7 +96,7 @@ check_thenelse_OX <- function(.then, .else) { # nolint
#' then `[!idx]`, if `integer` then `[-idx]`
#'
#' @inheritParams validate_f_out
#' @return same class as `idx`
#' @return object identical to `idx` input but with inverted values.
#' @keywords internal
invert_indices <- function(idx) {
if (is.logical(idx)) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[![Check and
deploy](https://github.com/gogonzo/ox/workflows/Check%20and%20deploy/badge.svg)](https://github.com/gogonzo/ox/actions)
[![](https://ci.appveyor.com/api/projects/status/github/gogonzo/ox?branch=master&svg=true)](https://ci.appveyor.com/project/gogonzo/ox)
[![](https://ci.appveyor.com/api/projects/status/github/gogonzo/ox?branch=main&svg=true)](https://ci.appveyor.com/project/gogonzo/ox)
[![](https://codecov.io/gh/gogonzo/ox/branch/main/graph/badge.svg)](https://codecov.io/gh/gogonzo/ox/branch/main)

<!-- badges: end -->
Expand Down
2 changes: 1 addition & 1 deletion man/OX_default.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/check_thenelse_OX.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/invert_indices.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/ox.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions man/vectorized-ox.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 199bfde

Please sign in to comment.