Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/HughParsonage/hutils
Browse files Browse the repository at this point in the history
  • Loading branch information
HughParsonage committed May 12, 2018
2 parents 46e9fbf + d3d755e commit f6e2f39
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 102 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ language: R
matrix:
include:
- r: release
env:
- HUTILS_BENCHMARK=TRUE
env:
- HUTILS_BENCHMARK=TRUE
- r: release
- HUTILS_BENCHMARK=FALSE
env:
- HUTILS_BENCHMARK=FALSE
- r: devel
cache: packages
latex: true
Expand Down
5 changes: 3 additions & 2 deletions R/auc.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' an ordered factor, or the unique values are \code{FALSE} and \code{TRUE} (case-insensitively).
#' Anything else is an error.
#' @param pred Numeric (double) vector the same length as \code{actual} giving the predicted probability of \code{TRUE}. Must be a numeric vector the same length as \code{actual}.
#' @source Source code based on \code{\link[Metrics]{auc}} from Ben Hamner and Michael Frasco and Erin LeDell from the Metrics package.
#' @source Source code based on \code{Metrics::auc} from Ben Hamner and Michael Frasco and Erin LeDell from the Metrics package.
#' @export auc

#' @author
Expand All @@ -30,7 +30,8 @@ auc <- function(actual, pred) {
if (!is.double(pred)) {
# Switch the values
if (is.logical(pred) && is.double(actual)) {
# Immeediate return
# Immediate return
message("`pred` was type logical and `actual` was type double, so interpreting as auc(pred, actual). Set to auc(actual, pred) for standard behaviour.")
return(auc(actual = pred, pred = actual))
}

Expand Down
25 changes: 10 additions & 15 deletions inst/doc/hutils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ na <- sample(letters, size = 100e3, replace = TRUE)

microbenchmark(dplyr = dplyr::if_else(cnd, yes, no, na),
hutils = hutils::if_else(cnd, yes, no, na),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print

cnd <- sample(c(TRUE, FALSE, NA), size = 100e3, replace = TRUE)
yes <- sample(letters, size = 1, replace = TRUE)
Expand All @@ -50,9 +49,8 @@ na <- sample(letters, size = 1, replace = TRUE)

microbenchmark(dplyr = dplyr::if_else(cnd, yes, no, na),
hutils = hutils::if_else(cnd, yes, no, na),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print

## ----compare_coalesce----------------------------------------------------
x <- sample(c(letters, NA), size = 100e3, replace = TRUE)
Expand All @@ -62,28 +60,25 @@ C <- sample(c(letters, NA), size = 100e3, replace = TRUE)

microbenchmark(dplyr = dplyr::coalesce(x, A, B, C),
hutils = hutils::coalesce(x, A, B, C),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print

## ----compare_coalesce_short_circuit_x------------------------------------
x <- sample(c(letters), size = 100e3, replace = TRUE)

microbenchmark(dplyr = dplyr::coalesce(x, A, B, C),
hutils = hutils::coalesce(x, A, B, C),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print

## ----compare_coalesce_short_circuit_A------------------------------------
x <- sample(c(letters, NA), size = 100e3, replace = TRUE)
A <- sample(c(letters), size = 100e3, replace = TRUE)

microbenchmark(dplyr = dplyr::coalesce(x, A, B, C),
hutils = hutils::coalesce(x, A, B, C),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print

## ----canonical_drop_DT---------------------------------------------------
DT <- data.table(A = 1:5, B = 1:5, C = 1:5)
Expand Down
25 changes: 10 additions & 15 deletions inst/doc/hutils.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ na <- sample(letters, size = 100e3, replace = TRUE)
microbenchmark(dplyr = dplyr::if_else(cnd, yes, no, na),
hutils = hutils::if_else(cnd, yes, no, na),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print
cnd <- sample(c(TRUE, FALSE, NA), size = 100e3, replace = TRUE)
yes <- sample(letters, size = 1, replace = TRUE)
Expand All @@ -98,9 +97,8 @@ na <- sample(letters, size = 1, replace = TRUE)
microbenchmark(dplyr = dplyr::if_else(cnd, yes, no, na),
hutils = hutils::if_else(cnd, yes, no, na),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print
```

This speed advantage also appears to be true of `coalesce`:
Expand All @@ -113,9 +111,8 @@ C <- sample(c(letters, NA), size = 100e3, replace = TRUE)
microbenchmark(dplyr = dplyr::coalesce(x, A, B, C),
hutils = hutils::coalesce(x, A, B, C),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print
```

especially during short-circuits:
Expand All @@ -125,9 +122,8 @@ x <- sample(c(letters), size = 100e3, replace = TRUE)
microbenchmark(dplyr = dplyr::coalesce(x, A, B, C),
hutils = hutils::coalesce(x, A, B, C),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print
```

```{r compare_coalesce_short_circuit_A}
Expand All @@ -136,9 +132,8 @@ A <- sample(c(letters), size = 100e3, replace = TRUE)
microbenchmark(dplyr = dplyr::coalesce(x, A, B, C),
hutils = hutils::coalesce(x, A, B, C),
check = my_check) %T>%
print %>%
autoplot
check = my_check) %>%
print
```


Expand Down
Loading

0 comments on commit f6e2f39

Please sign in to comment.