Skip to content

Commit aa78add

Browse files
committed
add this_in_that
1 parent f2d9fe1 commit aa78add

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export(show_connections)
9090
export(substrev)
9191
export(theme_mwk)
9292
export(theme_mwk_caption_text)
93+
export(this_in_that)
9394
export(trim_ws)
9495
export(un_zip)
9596
export(write_function)

R/this_in_that.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#' Where is this in that?
2+
#'
3+
#' Looks up (matches) the position of \code{this} in \code{that} (table)
4+
#'
5+
#' @param this Values to look up in that
6+
#' @param that Value positions matched to this
7+
#' @param value Optional, values to be returned rather than the default, which
8+
#' returns positions (integers)
9+
#' @export
10+
this_in_that <- function(this, that, value = NULL) {
11+
m <- match(this, that)
12+
if (is.null(value)) {
13+
return(m)
14+
}
15+
if (length(that) != length(value)) {
16+
stop("'value' must be same length as 'that' (table)", call. = FALSE)
17+
}
18+
value[m]
19+
}

man/this_in_that.Rd

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

0 commit comments

Comments
 (0)