Skip to content

Commit

Permalink
Merge pull request #30 from r-world-devs/krystian.readjusting-ids
Browse files Browse the repository at this point in the history
Readjust step and filter ids after removing it.
  • Loading branch information
krystian8207 authored Feb 27, 2023
2 parents 8021a08 + bb4eb3e commit 82a402e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: cohortBuilder
Type: Package
Title: Data Source Agnostic Filtering Tools
Version: 0.1.2
Version: 0.1.2.9000
Authors@R:
c(person('Krystian', 'Igras',
email = '[email protected]',
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# cohortBuilder 0.1.2
# cohortBuilder (development version)

* Changed the way reproducible code is returned. Now more flexibility is allowed with using e.g. `.repro_code_tweak` method.
* The `tblist` source reproducible code is now using pipe chains for each dataset filtering.
* Optimized filtering with having cache computed only for active filters.
* Properly readjust steps and filters ids after step is removed.

# cohortBuilder 0.1.1

Expand Down
6 changes: 4 additions & 2 deletions R/cohort_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ Cohort <- R6::R6Class(
run_hooks(hook$pre, self, private, step_id)

step_id <- as.character(step_id)
clear_data_ids <- steps_range(step_id, rev(names(private$steps))[1])
private$steps[[step_id]] <- NULL
private$cache[[step_id]] <- NULL
private$data_objects[steps_range(step_id, length(private$data_objects))] <- NULL
private$cache[clear_data_ids] <- NULL
private$data_objects[clear_data_ids] <- NULL
private$steps <- adjust_names(private$steps)
private$steps <- purrr::imodify(private$steps, readjust_step)
if (!is.null(private$steps) && run_flow) {
self$run_flow(min_step = step_id)
}
Expand Down
5 changes: 5 additions & 0 deletions R/list_operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ rename_item <- function(list_obj, old_name, new_name) {
return(list_obj)
}

modify_item <- function(list_obj, new_val, what) {
list_obj[[what]] <- new_val
return(list_obj)
}

#' Get function definition
#'
#' Whenever the function with provided name exists anywhere, the one is
Expand Down
7 changes: 7 additions & 0 deletions R/step.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ steps_range <- function(from, to) {
)
}

readjust_step <- function(step, new_id) {
step$id <- new_id
step$filters <- purrr::modify(step$filters, modify_item, new_val = new_id, what = "step_id")

return(step)
}

prev_step <- function(idx) {
as.character(as.integer(idx) - 1)
}
Expand Down
2 changes: 1 addition & 1 deletion renv/settings.dcf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
external.libraries:
ignored.packages:
ignored.packages: cohortBuilder
package.dependency.fields: Imports, Depends, LinkingTo
r.version:
snapshot.type: all
Expand Down

0 comments on commit 82a402e

Please sign in to comment.