Skip to content

Commit

Permalink
Merge pull request #161 from atorus-research/gh_issue_154
Browse files Browse the repository at this point in the history
Gh issue 154
  • Loading branch information
asbates committed Dec 15, 2023
2 parents a30dd2e + 1daabae commit 64a0dc2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ S3method(set_denoms_by,count_layer)
S3method(set_denoms_by,shift_layer)
S3method(set_format_strings,count_layer)
S3method(set_format_strings,desc_layer)
S3method(set_format_strings,shift_layer)
S3method(set_where,tplyr_layer)
S3method(set_where,tplyr_table)
S3method(str,f_str)
Expand Down
4 changes: 2 additions & 2 deletions R/layering.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ add_layer <- function(parent, layer, name=NULL) {

# Insert the `parent` argument into the topmost call of the layer code
# (i.e. if any pipes %>% then pull out the left most call and modify it)
l <- modify_nested_call(layer, parent=parent)
l <- quo_get_expr(modify_nested_call(layer, parent=parent))

# Evaluate the layer and grab `tplyr_layer` or `tplyr_subgroup_layer` object
executed_layer <- list(eval(quo_get_expr(l)))
executed_layer <- list(eval(l, envir=caller_env()))

# Attach the name
names(executed_layer) <- name
Expand Down
1 change: 1 addition & 0 deletions R/set_format_strings.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ set_format_strings.count_layer <- function(e, ...) {
e
}

#' @export
set_format_strings.shift_layer <- function(e, ...) {

dots <- list2(...)
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-layering.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,22 @@ test_that("Layers accept names when specified", {

})

test_that("add_layer can see calling environment objects", {
tfunc <- function(){

prec <- tibble::tribble(
~vs, ~max_int, ~max_dec,
0, 1, 1,
1, 2, 2
)

tplyr_table(mtcars, gear) %>%
add_layer(
group_desc(wt, by = vs) %>%
set_precision_data(prec)
)
}

expect_silent(tfunc())
})

0 comments on commit 64a0dc2

Please sign in to comment.