Skip to content

Commit

Permalink
Conditionally pass index via features()
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Mar 16, 2021
1 parent 9684c8b commit f245e0d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/features.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ features_impl <- function(.tbl, .var, features, ...){

# Compute response
key_dt <- key_data(.tbl)
idx <- index_var(.tbl)
.tbl <- as_tibble(.tbl)
if(NCOL(key_dt) > 1){
.tbl <- dplyr::new_grouped_df(.tbl, key_dt)
Expand All @@ -26,6 +27,9 @@ features_impl <- function(.tbl, .var, features, ...){
fmls <- formals(fn)[-1]
fn_safe <- safely(fn, tibble(.rows = 1))
res <- transpose(map(key_dt[[".rows"]], function(i){
# Add index to inputs
dots$.index <- .tbl[[idx]][i]
# Evaluate feature
out <- do.call(fn_safe, c(list(x[i]), dots[intersect(names(fmls), names(dots))]))
if(is.null(names(out[["result"]])))
names(out[["result"]]) <- paste0("..?", seq_along(out[["result"]]))
Expand Down

0 comments on commit f245e0d

Please sign in to comment.