insightsengineering / insightsengineering/teal.data

objects with reference semantics can break containment of `qenv`

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

Description

Objects that have reference semantics (_e.g._ environments, R6 objects, data.table), when created in the global environment and packaged into `teal_data`, allow for modifying the contents of `teal_data` from without.

```
library(teal.data)
library(data.table)

d1 <- as.data.table(iris)
td <- teal_data(d1 = d1, code = quote(d1 <- as.data.table(iris)))
within(td, print(head(d1)))
get_code(td) |> cat()

d1[, species := as.integer(Species)]
within(td, print(head(d1)))
```

This is a potential breach in code reproducibility.

----

Note that once code is evaluated `within` `teal_data`, the result is a deep copy because `@env` is cloned under the hood.
```
tdd <- within(td, d1 <- head(d1))
within(tdd, print(d1))
within(td, print(d1))
```

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.