insightsengineering / insightsengineering/teal.data

[Question]: Making easier to add piped expression to qenv

Open
#369 0 comments 0 reactions 0 assignees View on GitHub
core question
Dominant language
R
Stars
11
Forks
9
PR merge metrics
No merged PRs in 30d

Description

### What is your question?

With `within` is very easy to add a complete expression to qenv.

The pipe has the benefit of reducing the allocation of variables and removing a parameter as is passed implicitly and potentially make code more readable.
R users use/expect pipes (`%>%` and `|>` mostly) and often they are created step by step.
If the piped expression is not completed it results in an error, so module developers need to write first the complete expression and then add it to the qenv/teal_data:

``` r
library("qenv")
q <- within(qenv(), {
p <- penguins
})

within(q, {
p %>%
subset(!is.na(sex)) %>%
})
#> Error: unexpected '}' in:
#> " subset(!is.na(sex)) %>%
#> }"
```

It would be great if there were some method/function to be able to append an incomplete piped expression to be continued.
An idea:

```r
q2 <- add_pipe(q, {p <- p %>% subset(!is.na(sex))}, pipe = "%>%")
cat(get_code(q2))
#> p <- penguins
#> p<- p %>% subset(!is.na(sex)) %>% { }

q3 <- add_pipe(q2, {head()}, pipe = "")
cat(get_code(q3))
#> p <- penguins
#> p <- p %>% subset(!is.na(sex)) %>% head()
```

Adding an empty character instead of the (default?) pipe could signal the end of the pipeable expression.
Only then the code would be verified.

### 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.