Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce teal_data class #178

Merged
merged 92 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
e622149
any data possible
gogonzo Aug 14, 2023
9827de3
Merge remote-tracking branch 'origin/main' into refactor
gogonzo Aug 14, 2023
2daf83a
Merge remote-tracking branch 'origin/main' into refactor
gogonzo Aug 15, 2023
bef092f
ddl
gogonzo Aug 15, 2023
3f723f3
Merge bef092fd1955e566716e9d182b647657d1eac1ca into ba573f2544bf8591e…
gogonzo Aug 15, 2023
5e3c0cb
[skip actions] Restyle files
github-actions[bot] Aug 15, 2023
7429b55
adjust to teal
gogonzo Aug 15, 2023
e964b95
fix
gogonzo Aug 15, 2023
1b1ebc6
Merge e964b95be5111216e924621b7793ff046249de99 into ba573f2544bf8591e…
gogonzo Aug 15, 2023
3f37efe
[skip actions] Restyle files
github-actions[bot] Aug 15, 2023
212806c
change arg names
gogonzo Aug 16, 2023
7d9e2b0
Merge branch 'main' into refactor
gogonzo Sep 4, 2023
7edaf2a
cleanup builds
m7pr Sep 7, 2023
b30029b
@anverissimo review
gogonzo Sep 7, 2023
2248740
Merge remote-tracking branch 'origin/main' into refactor
gogonzo Sep 28, 2023
1ca4cb1
ddl alternative (#167)
chlebowa Sep 29, 2023
6504197
ddl WIP
gogonzo Sep 29, 2023
d067b93
POC
gogonzo Sep 29, 2023
56a7b2d
tdata -> teal_data
gogonzo Sep 29, 2023
f3876df
mask_args -> input_mask
gogonzo Oct 3, 2023
c407adf
online_args -> input
gogonzo Oct 3, 2023
5443613
ddl_run - input can be of class "reactivevalues"
gogonzo Oct 3, 2023
48e0f3b
handling datanames information
gogonzo Oct 3, 2023
6b46e4c
ddl from teal.data to teal
gogonzo Oct 3, 2023
2c9da20
teal_data class only
gogonzo Oct 4, 2023
fc853ad
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 4, 2023
b56ee4e
remove to_relational for classes which doesn't need transformation
gogonzo Oct 4, 2023
4ff57d0
specify datanames when more objects in environment
gogonzo Oct 4, 2023
32adc7c
Fix the unit tests for the teal_data refactor (#172)
vedhav Oct 5, 2023
7300049
reload NAMESPACE
gogonzo Oct 5, 2023
4900aef
adding temporary mutate_data for teal_data
gogonzo Oct 5, 2023
f7204f4
fixing preprocessing-data vignette
gogonzo Oct 5, 2023
67f96e4
waiting for parser
gogonzo Oct 5, 2023
801bc72
preparing to use parser
gogonzo Oct 5, 2023
7118d58
teal_data no longer returns TealData when data are available.
gogonzo Oct 5, 2023
c461980
fix
gogonzo Oct 5, 2023
75095ec
wrong package namespace for get_code
gogonzo Oct 5, 2023
36d4544
reverting breaking changes
gogonzo Oct 5, 2023
2fb8a39
fixing R cmd check
gogonzo Oct 5, 2023
0e26f43
new_teal_data(env) new_teal_data(data)
gogonzo Oct 6, 2023
e62f3a7
fixing namespace warning
gogonzo Oct 6, 2023
2680837
following changes in teal.code
gogonzo Oct 9, 2023
4f26d55
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 9, 2023
75f0890
fix
gogonzo Oct 10, 2023
2c0e3f7
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 10, 2023
7cb1986
Merge remote-tracking branch 'origin/main' into teal_data@main
gogonzo Oct 17, 2023
55d0dbc
need higher version of teal.code - code slot is a character
gogonzo Oct 17, 2023
9b3c303
update pkgdown
gogonzo Oct 18, 2023
985d06c
link S4 class
gogonzo Oct 18, 2023
0bb43d8
fix staged.deps
gogonzo Oct 19, 2023
1720d43
fix spelling
gogonzo Oct 19, 2023
b3cea7d
new teal_data examples in the docs
gogonzo Oct 19, 2023
67dea47
- only one constructor for teal_data
gogonzo Oct 20, 2023
d4a8a5d
Merge 67dea470f6fddaea1ef4823cd3ff736efc8f8f80 into c04b7edef44d80fd4…
gogonzo Oct 20, 2023
d869de6
[skip actions] Restyle files
github-actions[bot] Oct 20, 2023
b944347
fix asserts
gogonzo Oct 20, 2023
2485c0b
Merge b94434792cd982244b9c315817a61f7c593ca501 into c04b7edef44d80fd4…
gogonzo Oct 20, 2023
b7d7038
[skip actions] Restyle files
github-actions[bot] Oct 20, 2023
095a9be
fix spelling
gogonzo Oct 20, 2023
1a08953
fix error. Todo: resolve dependency on format_expression
gogonzo Oct 23, 2023
9fb959d
include format_expression to the internals of teal.data -
gogonzo Oct 23, 2023
904998e
Merge 9fb959d5db69ec3278e7918bbad29ef304bf6df8 into c04b7edef44d80fd4…
gogonzo Oct 23, 2023
d926022
[skip actions] Restyle files
github-actions[bot] Oct 23, 2023
8a7dbc4
fix constructor docs of new_teal_data
gogonzo Oct 23, 2023
a3ebc25
Apply suggestions from code review
gogonzo Oct 23, 2023
d8be870
fix tests for teal_data
gogonzo Oct 23, 2023
8348640
Merge d8be8705e8edd0e6ede85909c5fbec4f5822044a into c04b7edef44d80fd4…
gogonzo Oct 23, 2023
8f3b812
[skip actions] Restyle files
github-actions[bot] Oct 23, 2023
bb6e0ff
add test for locked environment
gogonzo Oct 23, 2023
18e1055
linking to GH discussion page
gogonzo Oct 24, 2023
0e727c7
Simplifies data constructor for primary keys in `join_keys` (#179)
averissimo Oct 25, 2023
3f93eae
Merge 0e727c7cb39a8bf89d821de995182b35f9e625c3 into c04b7edef44d80fd4…
gogonzo Oct 25, 2023
cebb61f
[skip actions] Restyle files
github-actions[bot] Oct 25, 2023
4a0aeb9
further constructor simplification simplification
gogonzo Oct 25, 2023
f3de72c
tidyup docs
gogonzo Oct 25, 2023
996d080
fix lintr
gogonzo Oct 25, 2023
4c03c22
- rename keys to join_keys in new_teal_data
gogonzo Oct 25, 2023
5936220
lintr fix
gogonzo Oct 25, 2023
88fc42d
fix tests
gogonzo Oct 25, 2023
2355695
move get_join_keys.default from teal
gogonzo Oct 25, 2023
bfa77c1
add get_join_keys for TealData
gogonzo Oct 25, 2023
9c73c29
add `datanames` function (#181)
chlebowa Oct 27, 2023
a1e092c
to support dynamic list
gogonzo Oct 27, 2023
2fdfeed
Apply suggestions from code review
gogonzo Oct 27, 2023
4dd52bd
@chlebowa review
gogonzo Oct 30, 2023
f10d94a
@chlebowa
gogonzo Oct 30, 2023
ffa1e00
update documentation in teal_data.R
Oct 30, 2023
7771928
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 30, 2023
d7b3bcd
using [fun()] in roxygen2 docs
gogonzo Oct 30, 2023
3bc4e6b
initialize empty teal_data
gogonzo Oct 30, 2023
0dc21e0
[skip actions] Roxygen Man Pages Auto Update
dependabot-preview[bot] Oct 30, 2023
5ba4f99
empty
gogonzo Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Imports:
shinyjs,
stats,
teal.logger (>= 0.1.1),
teal.code (>= 0.4.1.9003),
pawelru marked this conversation as resolved.
Show resolved Hide resolved
utils,
yaml (>= 1.1.0)
Suggests:
Expand All @@ -57,7 +58,7 @@ Config/Needs/verdepcheck: rstudio/shiny, mllg/checkmate,
yaml=vubiostat/r-yaml, rstudio/bslib, tidyverse/dplyr, yihui/knitr,
tidyverse/magrittr, bioc::MultiAssayExperiment, tidyverse/readr,
rstudio/reticulate, rstudio/rmarkdown, bioc::SummarizedExperiment,
r-lib/testthat, r-lib/withr
r-lib/testthat, r-lib/withr, insightsengineering/teal.code
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
Config/Needs/website: insightsengineering/nesttemplate
Encoding: UTF-8
Language: en-US
Expand Down
9 changes: 7 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ S3method(get_code,default)
S3method(get_dataname,TealDataAbstract)
S3method(get_dataname,TealDataset)
S3method(get_dataname,TealDatasetConnector)
S3method(get_dataname,teal_data)
S3method(get_dataset,TealDataAbstract)
S3method(get_dataset,TealDataset)
S3method(get_dataset,TealDatasetConnector)
Expand All @@ -20,6 +21,9 @@ S3method(get_dataset_label,TealDatasetConnector)
S3method(get_datasets,TealDataAbstract)
S3method(get_datasets,TealDataset)
S3method(get_datasets,TealDatasetConnector)
S3method(get_datasets,teal_data)
S3method(get_join_keys,TealData)
S3method(get_join_keys,teal_data)
S3method(get_key_duplicates,TealDataset)
S3method(get_key_duplicates,data.frame)
S3method(get_keys,TealDataAbstract)
Expand Down Expand Up @@ -50,7 +54,6 @@ S3method(set_keys,TealDataAbstract)
S3method(set_keys,TealDataset)
S3method(set_keys,TealDatasetConnector)
S3method(to_relational_data,MultiAssayExperiment)
S3method(to_relational_data,TealData)
S3method(to_relational_data,TealDataset)
S3method(to_relational_data,TealDatasetConnector)
S3method(to_relational_data,data.frame)
Expand Down Expand Up @@ -89,6 +92,7 @@ export(get_dataname)
export(get_dataset)
export(get_dataset_label)
export(get_datasets)
export(get_join_keys)
export(get_key_duplicates)
export(get_keys)
export(get_labels)
Expand Down Expand Up @@ -118,7 +122,8 @@ export(teal_data_file)
export(to_relational_data)
export(validate_metadata)
import(shiny)
import(teal.code)
importFrom(digest,digest)
importFrom(logger,log_trace)
importFrom(shinyjs,show)
importFrom(shinyjs,useShinyjs)
importFrom(stats,setNames)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# teal.data 0.3.0.9007

### Breaking changes

* Introduced new data class (`teal_data`) which replaces deprecated `TealData`. New data class becomes a standard input for whole `teal` framework.
* Deprecated `teal_data` constructor when `TealDataset`, `TealDatasetConnector` or `TealDataConnector` objects are provided. New delayed data loading functions introduced in `teal` package.

### Miscellaneous
* Specified minimal version of package dependencies.

Expand Down
142 changes: 61 additions & 81 deletions R/cdisc_data.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
#' Data input for teal app
#'
#' @description `r lifecycle::badge("stable")`
#' Function takes datasets and creates `TealData` object which can be used in `teal` applications.
#' Function is a wrapper around [teal_data()] and guesses `join_keys`
#' for given datasets which names match ADAM datasets names.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' for given datasets which names match ADAM datasets names.
#' for given datasets whose names match ADAM datasets names.

#'
#' @note This function does not automatically assign keys to `TealDataset`
#' and `TealDatasetConnector` objects passed to it. If the keys are needed
#' they should be assigned before calling `cdisc_data`. See example:
#' ```
#' test_dataset <- dataset("ADAE", teal.data::example_cdisc_data("ADAE")) # does not have keys
#' test_adsl <- cdisc_dataset("ADSL", teal.data::example_cdisc_data("ADSL"))
#' test_data <- cdisc_data(test_dataset, test_adsl)
#' get_keys(test_data, "ADAE") # returns character(0)
#'
#' test_dataset <- cdisc_dataset("ADAE", teal.data::example_cdisc_data("ADAE"))
#' test_data <- cdisc_data(test_dataset, test_adsl)
#' get_keys(test_data, "ADAE") # returns [1] "STUDYID" "USUBJID" "ASTDTM" "AETERM" "AESEQ"
#' ```
#' @inheritParams teal_data
#' @param ... (`TealDataConnector`, `TealDataset` or
#' `TealDatasetConnector`) elements to include.
#' @param join_keys (`JoinKeys`) or a single (`JoinKeySet`)\cr
#' (optional) object with datasets column names used for joining.
#' If empty then it would be automatically derived basing on intersection of datasets primary keys
#' If empty then it would be automatically derived basing on intersection of datasets primary keys.
#' For ADAM datasets it would be automatically derived.
#'
#' @return a `TealData` object
#' @return a `TealData` or `teal_data` object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should specify when

#'
#' @details This function checks if there were keys added to all data sets
#'
Expand All @@ -34,92 +21,85 @@
#' ADSL <- teal.data::example_cdisc_data("ADSL")
#' ADTTE <- teal.data::example_cdisc_data("ADTTE")
#'
#' # basic example
#' cdisc_data(
#' cdisc_dataset("ADSL", ADSL),
#' cdisc_dataset("ADTTE", ADTTE),
#' code = "ADSL <- teal.data::example_cdisc_data(\"ADSL\")
#' ADTTE <- teal.data::example_cdisc_data(\"ADTTE\")",
#' check = TRUE
#' )
#'
#' # Example with keys
#' cdisc_data(
#' cdisc_dataset("ADSL", ADSL,
#' keys = c("STUDYID", "USUBJID")
#' ),
#' cdisc_dataset("ADTTE", ADTTE,
#' keys = c("STUDYID", "USUBJID", "PARAMCD"),
#' parent = "ADSL"
#' ),
#' ADSL = ADSL,
#' ADTTE = ADTTE,
#' code = quote({
#' ADSL <- teal.data::example_cdisc_data("ADSL")
#' ADTTE <- teal.data::example_cdisc_data("ADTTE")
#' }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use code-push in examples? (empty cdisc_data followed by within)

#' join_keys = join_keys(
#' join_key(
#' "ADSL",
#' "ADTTE",
#' c("STUDYID" = "STUDYID", "USUBJID" = "USUBJID")
#' )
#' ),
#' code = "ADSL <- teal.data::example_cdisc_data(\"ADSL\")
#' ADTTE <- teal.data::example_cdisc_data(\"ADTTE\")",
#' check = TRUE
#' join_key("ADSL", "ADTTE", c("STUDYID" = "STUDYID", "USUBJID" = "USUBJID"))
#' )
#' )
cdisc_data <- function(...,
join_keys = teal.data::join_keys(),
code = "",
check = FALSE) {
data_objects <- list(...)
checkmate::assert_list(
data_objects,
types = c("TealDataset", "TealDatasetConnector", "TealDataConnector")
)

# todo: is it really important? - to remove
if (inherits(join_keys, "JoinKeySet")) {
join_keys <- teal.data::join_keys(join_keys)
}

update_join_keys_to_primary(data_objects, join_keys)

retrieve_parents <- function(x) {
tryCatch(
x$get_parent(),
error = function(cond) rep(character(0), length(x$get_datanames()))
if (
checkmate::test_list(data_objects, types = c("TealDataConnector", "TealDataset", "TealDatasetConnector"))
) {
lifecycle::deprecate_warn(
when = "0.3.1",
"cdisc_data(
data_objects = 'should use data directly. Using TealDatasetConnector and TealDataset is deprecated.'
)"
)
}
update_join_keys_to_primary(data_objects, join_keys)

new_parents_fun <- function(data_objects) {
lapply(data_objects, function(x) {
new_parents_fun <- function(data_objects) {
lapply(data_objects, function(x) {
if (inherits(x, "TealDataConnector")) {
unlist(new_parents_fun(x$get_items()), recursive = FALSE)
} else {
list(
tryCatch(
x$get_parent(),
error = function(cond) rep(character(0), length(x$get_datanames()))
)
)
}
})
}

new_parents <- unlist(new_parents_fun(data_objects), recursive = FALSE)

names(new_parents) <- unlist(lapply(data_objects, function(x) {
if (inherits(x, "TealDataConnector")) {
unlist(new_parents_fun(x$get_items()), recursive = FALSE)
lapply(x$get_items(), function(z) z$get_dataname())
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
} else {
list(retrieve_parents(x))
x$get_datanames()
}
})
}

new_parents <- unlist(new_parents_fun(data_objects), recursive = FALSE)
}))

names(new_parents) <- unlist(lapply(data_objects, function(x) {
if (inherits(x, "TealDataConnector")) {
lapply(x$get_items(), function(z) z$get_dataname())
} else {
x$get_datanames()
if (is_dag(new_parents)) {
stop("Cycle detected in a parent and child dataset graph.")
}
}))
join_keys$set_parents(new_parents)
join_keys$update_keys_given_parents()

if (is_dag(new_parents)) {
stop("Cycle detected in a parent and child dataset graph.")
}
join_keys$set_parents(new_parents)
join_keys$update_keys_given_parents()
x <- TealData$new(..., check = check, join_keys = join_keys)

x <- TealData$new(..., check = check, join_keys = join_keys)
if (length(code) > 0 && !identical(code, "")) {
x$set_pull_code(code = code)
}

if (length(code) > 0 && !identical(code, "")) {
x$set_pull_code(code = code)
x$check_reproducibility()
x$check_metadata()
x
} else {
if (!checkmate::test_names(names(data_objects), type = "named")) {
stop("Dot (`...`) arguments on `teal_data()` must be named.")
}
Copy link
Contributor

@pawelru pawelru Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to support "dynamic dots"?

I am thinking here about re-collecting dots with rlang:: dots_list which has in-built support for names assertions and others. This could be important from error message consistency reasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think that this could be a very neat feature implemented at relatively low cost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but at this moment this list could be named (new approach) and unnamed (old approach). So I can't just assert directly when obtaining ...

  data_objects <- list(...)
  if (checkmate::test_list(data_objects, types = c("TealDataConnector", "TealDataset", "TealDatasetConnector")) {
     # make TealData
   } else {
     if (!checkmate::test_names(names(data_objects), type = "named")) {
      stop("Dot (`...`) arguments on `teal_data()` must be named.")
    }
    # make teal_data
   
   }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would have to collect dots twice

if (old approach condition) {
  objs <- dots_list(..., .named = FALSE, <other>)
  ...
} else {
  objs <- dots_list(..., .named = TRUE, <other>)
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three times actually, because logical condition is based on output from ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok how about this:

objs <- dots_list(..., .named = FALSE, <other>)
if (condition(objs)) {
  ...
} else {
  objs <- dots_list(..., .named = TRUE, <other>)
  ...
}

Then after we hard deprecate old approach it would be just this:

  objs <- dots_list(..., .named = TRUE, <other>)
  ...

new_teal_data(data = data_objects, code = code, keys = join_keys)
}

x$check_reproducibility()
x$check_metadata()
return(x)
}

#' Load `TealData` object from a file
Expand Down
6 changes: 6 additions & 0 deletions R/get_dataname.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ get_dataname.TealDatasetConnector <- function(x) { # nolint
get_dataname.TealDataset <- function(x) { # nolint
return(x$get_dataname())
}

#' @rdname get_dataname
#' @export
get_dataname.teal_data <- function(x) { # nolint
return(x@datanames)
}
6 changes: 6 additions & 0 deletions R/get_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@ get_datasets.TealDatasetConnector <- function(x) { # nolint
get_datasets.TealDataset <- function(x) {
x
}

#' @rdname get_datasets
#' @export
get_datasets.teal_data <- function(x) {
as.list(x@env)[teal.data::get_dataname(x)]
}
20 changes: 20 additions & 0 deletions R/get_join_keys.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' Function to get join keys from a `` object
#' @param data `` - object to extract the join keys
#' @return Either `JoinKeys` object or `NULL` if no join keys
#' @export
get_join_keys <- function(data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you introduce a new method please check for possible replacement of old method for consistency reasons

❯ grep -r "get_join_keys()" --include="*.R" .
./R/module_teal_with_splash.R:        keys = data$get_join_keys()
./R/module_teal_with_splash.R:            keys = data$get_join_keys()
./R/module_nested_tabs.R:    datasets$get_join_keys(),

UseMethod("get_join_keys", data)
}


#' @rdname get_join_keys
#' @export
get_join_keys.teal_data <- function(data) {
data@join_keys
}

#' @rdname get_join_keys
#' @export
get_join_keys.TealData <- function(data) {
data$get_join_keys()
}
2 changes: 1 addition & 1 deletion R/teal.data.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#' @import shiny
#' @importFrom digest digest
#' @importFrom stats setNames
#' @importFrom shinyjs show
#' @importFrom shinyjs useShinyjs
pawelru marked this conversation as resolved.
Show resolved Hide resolved
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#' @importFrom logger log_trace
NULL
74 changes: 74 additions & 0 deletions R/teal_data-class.R
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
setOldClass("JoinKeys")

#' Reproducible data class.
#'
#' Reproducible data class basing on [`teal.code::qenv-class`].
#' Don't interact with slots directly, it is suggested to use methods instead
#' (see `methods(class = "teal_data")`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little aggressive. How about: please see methods to interact with class' slots.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I let you suggest the whole phrase. I don't agree with idea of writing documentation and commands with too polite language (what is too polite I don't know either as it depends who you talking with). I think it should be clear what should be done and what is not allowed for users.

I agree though too use softer language in the vignettes ;]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I let you suggest the whole phrase.

Don't mind if I do 😉

chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @name teal_data-class
#' @rdname teal_data-class
#'
#' @slot code (`character`) representing code necessary to reproduce the environment.
#' To extract the `code` please use [get_code()].
#' @slot env (`environment`) environment which content was generated by the evaluation
#' of the `code` slot. To extract variables from the environment please use [get_var()] or [`[[`].
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#' @slot id (`integer`) random identifier of the code element to make sure uniqueness
#' when joining.
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#' @slot warnings (`character`) the warnings output when evaluating the code.
#' To extract the `warnings` use [get_warnings()].
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#' @slot messages (`character`) the messages output when evaluating the code
pawelru marked this conversation as resolved.
Show resolved Hide resolved
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#' @slot join_keys (`JoinKeys`) object.
#' To extract the `join_keys` use [get_join_keys()].
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#' @slot datanames (`character`) names of datasets in `env`. Needed when non-dataset
#' objects are needed in the `env` slot.
#' To extract the `datanames` use [get_dataname()].
chlebowa marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @import teal.code
#' @keywords internal
setClass(
Class = "teal_data",
contains = "qenv",
slots = c(join_keys = "JoinKeys", datanames = "character"),
prototype = list(
join_keys = join_keys(),
datanames = character(0)
)
)

#' Initialize `teal_data` object
#'
#' Initialize `teal_data` object.
#' @name new_teal_data
#'
#' @param data (`named list`) List of data.
#' @param code (`character` or `language`) code to reproduce the `data`.
#' Accepts and stores comments also.
#' @param keys (`JoinKeys`) object
#' @param datanames (`character`) names of datasets passed to `data`.
#' Needed when non-dataset objects are needed in the `env` slot.
#' @rdname new_teal_data
#' @keywords internal
new_teal_data <- function(data, code = character(0), keys = join_keys(), datanames = names(data)) {
checkmate::assert_list(data)
checkmate::assert_class(keys, "JoinKeys")
checkmate::assert_character(datanames)
if (!any(is.language(code), is.character(code))) {
stop("`code` must be a character or language object.")
}
code <- teal.code:::format_expression(code)
gogonzo marked this conversation as resolved.
Show resolved Hide resolved

new_env <- rlang::env_clone(list2env(data), parent = parent.env(.GlobalEnv))
lockEnvironment(new_env, bindings = TRUE)

methods::new(
"teal_data",
env = new_env,
code = code,
warnings = "",
messages = "",
id = sample.int(.Machine$integer.max, size = 1L),
join_keys = keys,
datanames = datanames
)
}
Loading