Skip to content

Commit

Permalink
Merge pull request #33 from stscl/dev
Browse files Browse the repository at this point in the history
use `formula_varname`
  • Loading branch information
SpatLyu authored Jan 9, 2025
2 parents 86b6b25 + b4d3bf3 commit e552005
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
12 changes: 4 additions & 8 deletions R/fuzzyoverlay.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @return A numeric vector.
#' @export
#' @examples
#' set.seed(42)
#' sim = tibble::tibble(y = stats::runif(7,0,10),
#' x1 = c(1,rep(2,3),rep(3,3)),
#' x2 = c(rep(1,2),rep(2,2),rep(3,3)))
Expand All @@ -26,14 +27,9 @@ fuzzyoverlay = \(formula, data, method = "and"){

fuzzyf = ifelse(method == "and","which.min","which.max")

formula = stats::as.formula(formula)
formula.vars = all.vars(formula)
y = data[, formula.vars[1], drop = TRUE]
if (formula.vars[2] == "."){
xs = dplyr::select(data,-dplyr::any_of(formula.vars[1]))
} else {
xs = dplyr::select(data,dplyr::all_of(formula.vars[-1]))
}
formulavars = formula_varname(formula, data)
y = data[, formulavars[[1]], drop = TRUE]
xs = data[, formulavars[[2]]]
xs = xs %>%
dplyr::mutate(dplyr::across(dplyr::where(is.factor),
as.character)) %>%
Expand Down
1 change: 1 addition & 0 deletions man/fuzzyoverlay.Rd

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

0 comments on commit e552005

Please sign in to comment.