From f0b4ea7383bf5e6d03aef5451d7ffd92c21b8d76 Mon Sep 17 00:00:00 2001 From: Greg Freedman Ellis Date: Tue, 4 Aug 2020 11:38:15 -0500 Subject: [PATCH] alter categories used kwargs incorrectly --- R/expressions.R | 11 +++++------ tests/testthat/test-expressions.R | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/R/expressions.R b/R/expressions.R index a238fa852..88eedf142 100644 --- a/R/expressions.R +++ b/R/expressions.R @@ -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) { diff --git a/tests/testthat/test-expressions.R b/tests/testthat/test-expressions.R index 29558f428..43338585d 100644 --- a/tests/testthat/test-expressions.R +++ b/tests/testthat/test-expressions.R @@ -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"}]}}}' ) ) }) @@ -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"}]}}}' ) ) }) @@ -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"}]}}}' ) ) }) @@ -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"}]}}}' ) ) })