Skip to content

Commit

Permalink
alter categories used kwargs incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
gergness committed Aug 4, 2020
1 parent 312084d commit f0b4ea7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
11 changes: 5 additions & 6 deletions R/expressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,13 @@ alterCategoriesExpr <- function(
) {
isVarButNotType(x, c("Array", "Categorical"), "alterCategoriesExpr")

args <- list()
if (!is.null(categories)) args$categories <- alter_cats_get_cat_ids(x, categories)
if (!is.null(order)) args$order <- alter_cats_get_order_ids(x, category_order)
args <- list(fun = "alter_categories", x)
if (!is.null(categories)) args$categories <- list(value = alter_cats_get_cat_ids(x, categories)) # nolint
if (!is.null(category_order)) args$order <- list(value = alter_cats_get_order_ids(x, category_order))
if (!is.null(subvariables)) {
args$subvariables <- alter_cats_get_subvar_ids(x, subvariables)
args$subvariables <- list(value = alter_cats_get_subvar_ids(x, subvariables))
}

zfuncExpr("alter_categories", x, list(value = I(args)))
do.call(zfuncExpr, args)
}

alter_cats_get_cat_ids <- function(x, categories) {
Expand Down
22 changes: 11 additions & 11 deletions tests/testthat/test-expressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ with_mock_crunch({
expect_equal(
unclass(toJSON(expr@expression)),
paste0(
'{"function":"alter_categories","args":[{"variable":"https://app.crunch.io/api/datasets/1/variables/catarray/"},', # nolint
'{"value":{"categories":[{"id":1,"name":"AAA"}],"order":[2,1,-1],',
'"subvariables":[{"id":"subvar1","name":"ZZZ"}]}}]}'
'{"function":"alter_categories","args":[{"variable":"https://app.crunch.io/api/datasets/1/variables/catarray/"}],', # nolint
'"kwargs":{"categories":{"value":[{"id":1,"name":"AAA"}]},"order":{"value":[2,1,-1]},', #nolint
'"subvariables":{"value":[{"id":"subvar1","name":"ZZZ"}]}}}'
)
)
})
Expand All @@ -521,9 +521,9 @@ with_mock_crunch({
expect_equal(
unclass(toJSON(expr@expression)),
paste0(
'{"function":"alter_categories","args":[{"variable":"https://app.crunch.io/api/datasets/1/variables/catarray/"},', # nolint
'{"value":{"categories":[{"id":1,"name":"AAA"}],"order":[2,1,-1],',
'"subvariables":[{"id":"subvar1","name":"ZZZ"}]}}]}'
'{"function":"alter_categories","args":[{"variable":"https://app.crunch.io/api/datasets/1/variables/catarray/"}],', # nolint
'"kwargs":{"categories":{"value":[{"id":1,"name":"AAA"}]},"order":{"value":[2,1,-1]},', #nolint
'"subvariables":{"value":[{"id":"subvar1","name":"ZZZ"}]}}}'
)
)
})
Expand All @@ -538,8 +538,8 @@ with_mock_crunch({
expect_equal(
unclass(toJSON(expr@expression)),
paste0(
'{"function":"alter_categories","args":[{"variable":"https://app.crunch.io/api/datasets/1/variables/catarray/"},', # nolint
'{"value":{"subvariables":[{"id":"subvar1","name":"ZZZ"}]}}]}'
'{"function":"alter_categories","args":[{"variable":"https://app.crunch.io/api/datasets/1/variables/catarray/"}],', # nolint
'"kwargs":{"subvariables":{"value":[{"id":"subvar1","name":"ZZZ"}]}}}'
)
)
})
Expand All @@ -558,9 +558,9 @@ with_mock_crunch({
'{"function":"alter_categories","args":[{"function":"as_selected","args":',
'[{"function":"select_categories","args":',
'[{"variable":"https://app.crunch.io/api/datasets/1/variables/catarray/"},',
'{"value":["A"]}]}]},',
'{"value":{"categories":[{"id":1,"name":"AAA"}],"order":[2,1,-1],',
'"subvariables":[{"id":"subvar1","name":"ZZZ"}]}}]}'
'{"value":["A"]}]}]}],"kwargs":{',
'"categories":{"value":[{"id":1,"name":"AAA"}]},"order":{"value":[2,1,-1]},',
'"subvariables":{"value":[{"id":"subvar1","name":"ZZZ"}]}}}'
)
)
})
Expand Down

1 comment on commit f0b4ea7

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R/expressions.R:617:1: style: Lines should not be more than 100 characters.

if (!is.null(category_order)) args$order <- list(value = alter_cats_get_order_ids(x, category_order))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Please sign in to comment.