Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabBookResult returns aliases and name as "total" for all NumericVariable type questions #509

Open
1beb opened this issue Oct 4, 2020 · 1 comment

Comments

@1beb
Copy link
Contributor

1beb commented Oct 4, 2020

As the title specifies it appears that aliases returns as "total" for all NumericVariable type questions.

Here's a complete, but simple example:

library(crunch) 
# ds <- newExampleDataset()
ds <- loadDataset("Example dataset")
multitable <- newMultitable("~ `allpets`", ds)
r <- tabBook(multitable, dataset = ds[c("ndogs")])
aliases(r)
[1] "total"
# should be ndogs

In the example above the alias is not "total", it should be "ndogs"

@1beb 1beb changed the title TabBookResult returns aliases as "total" for all NumericVariable type questions TabBookResult returns aliases and name as "total" for all NumericVariable type questions Oct 5, 2020
@gergness
Copy link
Contributor

gergness commented Oct 19, 2020

Hey, I was able to trace this back to backend behavior. There are reasons that it works this way, but people agreed that it should be fixed, hopefully as we pay more attention to numeric variables with the incoming numeric arrays.

As a work-around, the "name" of the variable is included on the analysis page, so you can match it to the names of the dataset like so, to get back the aliases:

library(crunch) 
# ds <- newExampleDataset()
ds <- loadDataset("Example dataset")
multitable <- newMultitable("~ `allpets`", ds)
r <- tabBook(multitable, dataset = ds[c("ndogs")])


# Instead of: aliases(r)
get_tabbook_aliases <- function(tabbook, dataset) {
    var_info <- variables(dataset)
    vapply(tabbook$meta$analyses, function(analysis) {
        aliases(var_info[names(var_info) == analysis$name])
    }, "")
}

get_tabbook_aliases(r, ds)
#> [1] "ndogs"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants