Skip to content

Commit c1cba0f

Browse files
authored
datanames in vignettes (#357)
see insightsengineering/teal.code#239 Refers to #338 Modified a documentation a little bit to emphasize inheritance from environment.
1 parent f8869c1 commit c1cba0f

File tree

6 files changed

+60
-21
lines changed

6 files changed

+60
-21
lines changed

R/teal_data-constructor.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' @description
44
#' `r lifecycle::badge("stable")`
55
#'
6-
#' Universal function to pass data to teal application.
6+
#' Initializes a data for `teal` application.
77
#'
88
#' @param ... any number of objects (presumably data objects) provided as `name = value` pairs.
99
#'
@@ -14,10 +14,28 @@
1414
#' @param code (`character`, `language`) optional code to reproduce the datasets provided in `...`.
1515
#' Note this code is not executed and the `teal_data` may not be reproducible
1616
#'
17-
#' Use [verify()] to verify code reproducibility .
17+
#' Use [verify()] to verify code reproducibility.
18+
#'
19+
#' @details
20+
#'
21+
#' A `teal_data` is meant to be used for reproducibility purposes. The class inherits from
22+
#' [`teal.data::qenv`] and we encourage to get familiar with \CRANpkg{teal.code} first.
23+
#' `teal_data` has following characteristics:
24+
#'
25+
#' - It inherits from the environment and methods such as [`$`], [get()], [ls()], [as.list()],
26+
#' [parent.env()] work out of the box.
27+
#' - `teal_data` is a locked environment, and data modification is only possible through the
28+
#' [teal.code::eval_code()] and [within.qenv()] functions.
29+
#' - It stores metadata about the code used to create the data (see [get_code()]).
30+
#' - It supports slicing (see [`teal.code::subset-qenv`])
31+
#' - Is immutable which means that each code evaluation does not modify the original `teal_data`
32+
#' environment directly.
33+
#' - It maintains information about relationships between datasets (see [join_keys()]).
1834
#'
1935
#' @return A `teal_data` object.
2036
#'
37+
#' @seealso [`teal.code::eval_code`], [get_code()], [join_keys()], [names.teal_data()]
38+
#'
2139
#' @export
2240
#'
2341
#' @examples

R/teal_data-show.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ setMethod("show", signature = "teal_data", function(object) {
1616
} else {
1717
cat("\u2716", "unverified teal_data object\n")
1818
}
19-
rlang::env_print(teal.code::get_env(object))
19+
methods::callNextMethod(object)
20+
invisible(object)
2021
})

man/cdisc_data.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/teal_data-class.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/teal_data.Rd

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/teal-data.Rmd

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ vignette: >
1111
# Introduction
1212

1313
The `teal.data` package specifies the data format used in `teal` applications.
14-
The `teal_data` class inherits from [`qenv`](https://insightsengineering.github.io/teal.code/latest-tag/articles/qenv.html) and is meant to be used for reproducibility purposes.
14+
15+
16+
A `teal_data` is meant to be used for reproducibility purposes. The class inherits from [`qenv`](https://insightsengineering.github.io/teal.code/latest-tag/articles/qenv.html) and we encourage to get familiar with [`teal.code`](https://insightsengineering.github.io/teal.code/latest-tag/) first. `teal_data` has following characteristics:
17+
18+
- It inherits from the environment and methods such as `$`, `get()`, `ls()`, `as.list()` work out of the box.
19+
- `teal_data` is a locked environment, and data modification is only possible through the `teal.code::eval_code()` and `within.qenv()` functions.
20+
- It stores metadata about the code used to create the data (see [reproducibility](#reproducibility)).
21+
- It supports slicing by `[`.
22+
- It is immutable which means that each code evaluation does not modify the original `teal_data` environment directly.
23+
- It maintains information about relationships between datasets (see [Join Keys](#relational-data-models)).
1524

1625
## Quick Start
1726

1827
To create an object of class `teal_data`, use the `teal_data` function.
19-
`teal_data` has a number of methods to manage relevant information in private class slots.
28+
`teal_data` has a number of methods to interact with the object.
2029

2130
```{r, results = 'hide', message = FALSE}
2231
library(teal.data)
@@ -46,23 +55,14 @@ get_code(my_data)
4655
4756
# get code just for specific object
4857
get_code(my_data, names = "data2")
58+
4959
# get datanames
5060
names(my_data)
5161
5262
# print
5363
print(my_data)
5464
```
5565

56-
57-
## `teal_data` characteristics
58-
59-
A `teal_data` object keeps the following information:
60-
61-
- `env` - an environment containing data.
62-
- `code` - a string containing code to reproduce `env` (details in [reproducibility](teal-data-reproducibility.html)).
63-
- `names` - a character vector listing objects of interest to `teal` modules (details in [this `teal` vignette](https://insightsengineering.github.io/teal/latest-tag/articles/including-data-in-teal-applications.html)).
64-
- `join_keys` - a `join_keys` object defining relationships between datasets (details in [Join Keys](join-keys.html)).
65-
6666
### Reproducibility
6767

6868
The primary function of `teal_data` is to provide reproducibility of data.
@@ -104,8 +104,8 @@ join_keys(my_data["child"])
104104

105105
### Hidden objects
106106

107-
An object is hidden in `teal_data` if its name starts with a dot (`.`).
108-
This can be used to pass auxiliary objects / function in the `teal_data` instance, without being visible in the `teal` summary and filter panel.
107+
An object is hidden in `teal_data` if its name starts with a dot (`.`). This can be used to pass auxiliary objects in
108+
the `teal_data` instance, without being visible in the `teal` summary and filter panel.
109109

110110
```{r}
111111
my_data <- teal_data()
@@ -114,5 +114,6 @@ my_data <- within(my_data, {
114114
.data2 <- data.frame(id = 1:20, data_id = c(1:10, 1:10), y = 21:30)
115115
})
116116
117+
ls(my_data)
117118
names(my_data)
118119
```

0 commit comments

Comments
 (0)