insightsengineering / insightsengineering/teal.slice

[Bug]: Unexpected column type on filtered data

Open
#527 0 comments 0 reactions 0 assignees View on GitHub
bug core
Dominant language
R
Stars
12
Forks
7
Avg merge
3d 31m
Merged PRs (30d)
1

Description

### What happened?

**Problem:** `get_data` method in `teal.slice::FilteredData` doesn't keep the same column type for possible values in `filtered` parameter

It was detected on https://github.com/insightsengineering/teal/pull/1038 and it only happens when there is a `join_keys` parent-child relationship.

**Impact:** As far as I can tell this doesn't affect users or is a problem, unless manually inspecting the contents.

Edge case: This surfaces when there is a conversion of `FilteredData` to `teal_data` and the initial hash of a dataname does not match the contents of `qenv` envirnoment object

**Reproducible code:** (needs {teal.slice}, {teal.code} and {teal.data})

``` r
td <- teal.data::teal_data(join_keys = teal.data::join_keys(teal.data::join_key("d1", "d2", c("pk" = "id")))) |>
within(d1 <- data.frame(id = 1:5, pk = c(2, 3, 2, 1, 4), val = 1:5)) |>
within(d2 <- data.frame(id = 1:5, value = 1:5))

datasets <- teal.slice::init_filtered_data(
x = sapply(c("d1", "d2"), function(dn) td[[dn]], simplify = FALSE),
join_keys = teal.data::join_keys(td)
)

# str() -----------------------------------------------------------------------

# filtered = TRUE
datasets$get_data("d2", filtered = TRUE) |>
shiny::isolate() |>
str()
#> 'data.frame': 5 obs. of 2 variables:
#> $ id : num 1 2 2 3 4
#> $ value: int 1 2 2 3 4

# filtered = FALSE
datasets$get_data("d2", filtered = FALSE) |>
shiny::isolate() |>
str()
#> 'data.frame': 5 obs. of 2 variables:
#> $ id : int 1 2 3 4 5
#> $ value: int 1 2 3 4 5

# rlang::hash() ---------------------------------------------------------------

# filtered = TRUE
datasets$get_data("d2", filtered = TRUE) |>
shiny::isolate() |>
rlang::hash()
#> [1] "fed25eb8e9c06544ff433b8cbb15379f"

# filtered = FALSE
datasets$get_data("d2", filtered = FALSE) |>
shiny::isolate() |>
rlang::hash()
#> [1] "6e30be195b7d914a1311672c3ebf4e4f"
```

Created on 2024-01-18 with [reprex v2.0.2](https://reprex.tidyverse.org)

### sessionInfo()

_No response_

### Relevant log output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct.

### Contribution Guidelines

- [X] I agree to follow this project's Contribution Guidelines.

### Security Policy

- [X] I agree to follow this project's Security Policy.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.