Skip to content

Commit 42ddd5a

Browse files
committed
Prepare new release v0.10.0
- Add new function toConditional() - Add magrittr to Suggests (used in 1 example) - Fix test (explicitly set stringsAsFactors)
1 parent c708c4f commit 42ddd5a

6 files changed

Lines changed: 62 additions & 4 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: kwb.utils
22
Title: General Utility Functions Developed at KWB
3-
Version: 0.9.0.9000
3+
Version: 0.10.0
44
Authors@R:
55
c(person(given = "Hauke",
66
family = "Sonnenberg",
@@ -25,6 +25,7 @@ Suggests:
2525
testthat,
2626
covr,
2727
knitr,
28+
magrittr,
2829
rmarkdown
2930
VignetteBuilder:
3031
knitr

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export(substSpecialChars)
247247
export(tableLookup)
248248
export(tempSubdirectory)
249249
export(textToObject)
250+
export(toConditional)
250251
export(toFactor)
251252
export(toFormula)
252253
export(toInches)

NEWS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Current
1+
# [kwb.utils 0.10.0](https://github.com/KWB-R/kwb.utils/releases/tag/v0.10.0) <small>2022-01-19</small>
22

33
* add findChanges(), to be used by kwb.utils::hsEventsOnChange()
4+
* add toConditional()
5+
* allow to pass a "path" to getAttribute()
46

57
# [kwb.utils 0.9.0](https://github.com/KWB-R/kwb.utils/releases/tag/v0.9.0) <small>2021-11-16</small>
68

@@ -9,7 +11,6 @@
911
* Add new private functions: enumeration(), hintAvailable(), hintNoSuch(),
1012
stopIsNotBut(),
1113
* checkForMissingColumns(), selectElements(): Use new private functions
12-
* Allow to pass a "path" to getAttribute()
1314

1415
# [kwb.utils 0.8.0](https://github.com/KWB-R/kwb.utils/releases/tag/v0.8.0) <small>2021-02-19</small>
1516

R/toConditional.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# toConditional ----------------------------------------------------------------
2+
3+
#' Convert Function to Function that is Called if Condition is Met
4+
#'
5+
#' @param FUN a function
6+
#' @export
7+
#' @examples
8+
#' square <- function(x) x^2
9+
#' negate <- function(x) -x
10+
#' `%>%` <- magrittr::`%>%`
11+
#' do_square <- TRUE
12+
#' do_negate <- TRUE
13+
#' 10 %>%
14+
#' toConditional(square)(do_square) %>%
15+
#' toConditional(negate)(do_negate)
16+
toConditional <- function(FUN)
17+
{
18+
stopifnot(is.function(FUN))
19+
20+
function(x, condition, ...) {
21+
22+
stopifnot(is.logical(condition), length(condition) == 1L)
23+
24+
if (! condition) {
25+
return(x)
26+
}
27+
28+
FUN(x, ...)
29+
}
30+
}

man/toConditional.Rd

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

tests/testthat/test_findChanges.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ test_that("findChanges() works", {
1616
expect_identical(f(c("a", "b", "b", "c")), data.frame(
1717
starts_at = c(1L, 2L, 4L),
1818
ends_at = c(1L, 3L, 4L),
19-
value = c("a", "b", "c")
19+
value = c("a", "b", "c"),
20+
stringsAsFactors = FALSE
2021
))
2122

2223
# Take care with real numbers!

0 commit comments

Comments
 (0)