Skip to content

Commit c424593

Browse files
committed
Modernize R package
1 parent 4ff0f71 commit c424593

File tree

12 files changed

+101
-84
lines changed

12 files changed

+101
-84
lines changed

DESCRIPTION

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
Package: rops
22
Title: Extended Binary Operators for Data Manipulation
33
Version: 0.0.1
4-
Authors@R: person("James", "Balamuta", email = "[email protected]", role = c("aut", "cre"))
4+
Authors@R: c(
5+
person(
6+
"James Joseph", "Balamuta",
7+
email = "[email protected]",
8+
role = c("aut", "cre"),
9+
comment = c(ORCID = "0000-0003-2826-8458")
10+
)
11+
)
512
Description: Provides a set of user defined infix operators and functions with
613
roots in other programming languages.
714
Depends:
8-
R (>= 3.3.0)
15+
R (>= 4.5.0)
916
License: MIT + file LICENSE
1017
Encoding: UTF-8
1118
LazyData: true
12-
RoxygenNote: 6.0.1
19+
RoxygenNote: 7.3.2
1320
Suggests: testthat,
1421
knitr,
1522
rmarkdown,

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
YEAR: 2016
1+
YEAR: 2016-2025
22
COPYRIGHT HOLDER: James Joseph Balamuta

R/coalescing-ops.R

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,34 @@
1010
#' @rdname null_coalesce
1111
#' @details
1212
#' The objective of the null coalescing operator is to simplify the expression:
13-
#' `if(is.null(x)){ y else { x }}` so that it is readable inline.
13+
#'
14+
#' ```r
15+
#' if(is.null(x)) {
16+
#' y
17+
#' else {
18+
#' x
19+
#' }
20+
#' ```
21+
#'
22+
#' This allows it to be readable inline.
1423
#'
1524
#' @section Warning:
1625
#' Due to the way objects are created within _R_, the `NULL` value
1726
#' is not able to be stored within \code{\link[=vector]{atomic vectors}}.
18-
#' However, the \code{\link{NULL}} value can be stored within a \code{\link{list}}.
19-
#' This operator will _not_ be triggered if \code{\link{NULL}} is within
27+
#' However, the [`NULL`] value can be stored within a [`list`].
28+
#' This operator will _not_ be triggered if [`NULL`] is within
2029
#' a list! That is, the RHS side will be returned.
2130
#' @export
22-
#' @seealso \code{\link{is.null}}, \code{\link{NULL}}
31+
#' @seealso [`is.null()`], [`NULL`]
2332
#' @examples
2433
#' # Null value
25-
#' x = NULL
34+
#' x <- NULL
2635
#'
2736
#' # Before
28-
#' y = if(is.null(x)){ "Unset" } else { x }
37+
#' y <- if(is.null(x)){ "Unset" } else { x }
2938
#'
3039
#' # After
31-
#' y = x %??% "Unset"
40+
#' y <- x %??% "Unset"
3241
#'
3342
#' # Concrete examples without variables
3443
#' # Returns 3 as the LHS is _not_ NULL
@@ -46,38 +55,42 @@
4655
#' # Coalesce operator
4756
#' NULL %??% 7 %??% 8
4857
#' @references
49-
#' \url{https://en.wikipedia.org/wiki/Null_coalescing_operator}
50-
`%??%` = function(x, y) if(is.null(x)) y else x
58+
#' <https://en.wikipedia.org/wiki/Null_coalescing_operator>
59+
`%??%` <- function(x, y) if(is.null(x)) y else x
5160

5261

5362
#' Missingness Coalescing Operator
5463
#'
5564
#' Substitutes values when `NA` is detected.
65+
#'
5666
#' @param x An possibly containing `NA` values
5767
#' @param y An object of equal length or a single value to be used in
5868
#' substitution
69+
#'
5970
#' @details
6071
#' The objective of this function is to provide an ability to substitute values
6172
#' for NA. However, it is important to note that _R_ is unique in the fact
6273
#' that it has an `NA` data type to represent missingness instead of relying
63-
#' on values being pre-coded (e.g. 0, -1111, et cetera). Thus, the simplicity
74+
#' on values being pre-coded (e.g. `0`, `-1111`, et cetera). Thus, the simplicity
6475
#' of this function comes with the disclaimer of:
6576
#'
6677
#' "An NA is the presence of an absence.
6778
#' Don't forget that some missing values are the absence of a presence"
68-
#' \href{https://twitter.com/hadleywickham/status/738802081448886272}{Hadley Wickham on Twitter}
79+
#'
80+
#' - Hadley Wickham on Twitter
81+
#'
6982
#' @export
7083
#' @references
71-
#' \url{https://support.office.com/en-us/article/IFNA-function-6626c961-a569-42fc-a49d-79b4951fd461}
84+
#' <https://support.office.com/en-us/article/IFNA-function-6626c961-a569-42fc-a49d-79b4951fd461>
7285
#' @examples
7386
#' # Data with missing values
74-
#' x = c(1, NA, NA, 4)
87+
#' x <- c(1, NA, NA, 4)
7588
#' # Substitution vector of equal length
76-
#' y = 1:4
89+
#' y <- 1:4
7790
#'
7891
#' # Replace NA with values in `y` vector
7992
#' ifna(x, y)
8093
#'
8194
#' # Replace NA with 5
8295
#' ifna(x, 5)
83-
ifna = function(x, y) ifelse(is.na(x), y, x)
96+
ifna <- function(x, y) ifelse(is.na(x), y, x)

R/equality-ops.R

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#'
55
#' @param x,y two data structures
66
#'
7-
#' @author JJB
87
#' @details
98
#' [base::identical()] function tests for an exact match meaning that
109
#' the variable's storage types match, the overall environment the variable
@@ -21,7 +20,7 @@
2120
#' @examples
2221
#' # Generate some data
2322
#' set.seed(991)
24-
#' x = y = rnorm(100)
23+
#' x <- y <- rnorm(100)
2524
#'
2625
#' # Returns TRUE as the objects are exactly the same
2726
#' x %==% y
@@ -30,7 +29,7 @@
3029
#' x %!=% y
3130
#'
3231
#' # Change data
33-
#' x2 = x+1
32+
#' x2 <- x+1
3433
#'
3534
#' # Returns FALSE as the data has changed.
3635
#' x2 %==% y
@@ -39,11 +38,11 @@
3938
#' x2 %!=% y
4039
#' @rdname obj_check
4140
#' @export
42-
`%==%` = function(x, y) identical(x, y)
41+
`%==%` <- function(x, y) identical(x, y)
4342

4443
#' @rdname obj_check
4544
#' @export
46-
`%!=%` = function(x, y) !identical(x, y)
45+
`%!=%` <- function(x, y) !identical(x, y)
4746

4847
#' Not in
4948
#'
@@ -52,13 +51,15 @@
5251
#'
5352
#' @inheritParams base::match
5453
#'
55-
#' @return A logical vector of `TRUE` or `FALSE` that indicates if a match was
56-
#' **not** found for each element of `x`.
57-
#' @author JJB
54+
#' @return
55+
#' A logical vector of `TRUE` or `FALSE` that indicates if a match was
56+
#' **not** found for each element of `x`.
57+
#'
5858
#' @details
59-
#' This operator is a modified version of the \code{\link[base]{\%in\%}} function.
59+
#' This operator is a modified version of the [`%in%`] function.
6060
#'
61-
#' @seealso \code{\link[base]{\%in\%}}
61+
#' @seealso
62+
#' [`%in%`]
6263
#'
6364
#' @examples
6465
#' # Returns TRUE as 2 is not found in the vector c(3, 4)
@@ -70,7 +71,7 @@
7071
#' # Vectorized variant that contains FALSE and TRUE
7172
#' c(1, 2) %notin% c(2, 3)
7273
#' @export
73-
`%notin%` = function(x, table) {
74+
`%notin%` <- function(x, table) {
7475
# Same as !(x %in% table)
7576
match(x, table, nomatch = 0L) == 0L
7677
}

R/int-ops.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#' Check for Whole (Integer) Numbers
22
#'
3-
#' Checks whether the submitted vector of values is a whole (integer) number.
3+
#' Checks whether the submitted vector of values is a whole (`integer`) number.
44
#'
5-
#' @param x A \code{numeric} value to check to see if it is an integer.
5+
#' @param x A `numeric` value to check to see if it is an `integer`.
66
#'
7-
#' @return A \code{boolean} value indicating whether the value is an integer or not.
7+
#' @return
8+
#' A `boolean` value indicating whether the value is an `integer` or not.
89
#'
9-
#' @author JJB
1010
#' @details
11-
#' The `is_whole` function provides a means to test whether
11+
#' The `is_whole()` function provides a means to test whether
1212
#' the [base::numeric()] or [base::integer()] is a part of the whole
1313
#' number span (integers). For example, `1` and `2` would be considered integers
1414
#' whereas `3.6` and `0.31` would be considered [base::numeric()]. The behavior
@@ -22,4 +22,6 @@
2222
#' is_whole(c(.4,.5,.6))
2323
#' is_whole(c(7,.8,9))
2424
#' @export
25-
is_whole = function(x) is.numeric(x) & floor(x) == x
25+
is_whole <- function(x) {
26+
is.numeric(x) & floor(x) == x
27+
}

R/sequences.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
#'
66
#' @inheritParams base::seq
77
#'
8-
#' @return An integer vector that is either empty or contains a sequence of
8+
#' @return
9+
#' An integer vector that is either empty or contains a sequence of
910
#' numbers.
1011
#'
11-
#' @author JJB
1212
#' @details
13-
#' Creating sequences using either [base::seq()] function or \code{\link[base]{Colon}}
13+
#' Creating sequences using either [base::seq()] function or [`:`]
1414
#' operator have a notable draw back of incorrectly generating positional
1515
#' indices when a vector is empty. For example, consider `x = NULL`. Then,
1616
#' the expression `1:length(x)` would evaluate to `1:0` which expands to `c(1,0)`.
1717
#' As a result, any \code{\link[base]{Control}} may inadvertantly trigger an out of bounds
1818
#' error on the initial run.
1919
#'
20-
#' The `safe_seq()` and \code{\%:\%} operator seeks to prevent this issue by enforcing
20+
#' The `safe_seq()` and `%:%` operator seeks to prevent this issue by enforcing
2121
#' either an ascending or descending sequence depending on the `by` condition.
22-
#' For the \code{\%:\%} operator, note that this is restricted to being _always_
22+
#' For the `%:%` operator, note that this is restricted to being _always_
2323
#' positive.
2424
#' @examples
2525
#' # Returns a sequence increasing by 1
@@ -35,7 +35,7 @@
3535
#' 1 %:% 4
3636
#' @rdname safe_seq
3737
#' @export
38-
safe_seq = function(from = 1L,
38+
safe_seq <- function(from = 1L,
3939
to = 1L,
4040
by = 1L) {
4141

@@ -66,4 +66,4 @@ safe_seq = function(from = 1L,
6666

6767
#' @rdname safe_seq
6868
#' @export
69-
`%:%` = function(from, to) { safe_seq(from, to, by = 1L) }
69+
`%:%` <- function(from, to) { safe_seq(from, to, by = 1L) }

man/grapes-notin-grapes.Rd

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ifna.Rd

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/is_whole.Rd

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/null_coalesce.Rd

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)