insightsengineering / insightsengineering/teal.code

[Feature Request]: Extend `within` to accept a custom parameter that links all lines to a dataname

Open
#200 12 comments 0 reactions 0 assignees View on GitHub
core enhancement
Dominant language
R
Stars
12
Forks
11
Avg merge
1d 17h
Merged PRs (30d)
1

Description

### Feature description

Extend `within.qenv(data, expr, links_to = NULL, ...)` so that `links_to` parameter will hint the code parser

The goal is that all the code in expr is hinted to one dataname (?or more?).

The `get_code` below would output the same code.

``` r
library(teal.code)
library(teal.data)

data_within <- teal_data() |> within({
options("AN_OPTION" = iris)
IRIS <- getOption("AN_OPTION")
}, links_to = "IRIS")

datanames(data_within) <- "IRIS"

get_code(data_within, datanames = "IRIS") |> cat()
#> IRIS <- getOption("AN_OPTION")

data_eval <- teal_data() |> eval_code("
options(\"AN_OPTION\" = iris) # @linksto IRIS
IRIS <- getOption(\"AN_OPTION\")
")

datanames(data_eval) <- "IRIS"

get_code(data_eval, datanames = "IRIS") |> cat()
#> options(AN_OPTION = iris)
#> IRIS <- getOption("AN_OPTION")
```

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

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