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

211 [.teal_data S3 method #346

Merged
merged 40 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
967c1c5
`[.teal_data` S3 method
m7pr Oct 28, 2024
362b982
provide prefix for utils::
m7pr Oct 28, 2024
a2610a3
fixing rdname
m7pr Oct 29, 2024
c01612f
rename teal_data.R to teal_data-constructor.R
m7pr Oct 29, 2024
fd4fe27
an attempt with NextMethod
m7pr Oct 29, 2024
f7894e5
add a warning
m7pr Oct 29, 2024
e53afc8
extend vignettes with `[` for teal_data
m7pr Oct 29, 2024
1ea9d8f
write tests for [.teal_data
m7pr Oct 29, 2024
220e46c
[skip style] [skip vbump] Restyle files
github-actions[bot] Oct 29, 2024
5f17af0
extned tests for different input class
m7pr Oct 30, 2024
6d3c3e8
Merge branch '211_subset@main' of https://github.com/insightsengineer…
m7pr Oct 30, 2024
39d9f37
remove NextMethod comments
m7pr Oct 30, 2024
b6c6955
extend tests with expect_warning
m7pr Oct 30, 2024
009bbc0
Update R/teal_data-extract.R
m7pr Oct 30, 2024
fc0d0c0
Update tests/testthat/test-extract.R
m7pr Oct 30, 2024
f74635a
remove unneeded roxygen2 tags
m7pr Oct 30, 2024
d3eb395
Update R/teal_data-constructor.R
m7pr Oct 30, 2024
5839f0d
warn about skipped names
m7pr Oct 30, 2024
269b77b
move tests to teal.code
m7pr Oct 30, 2024
1c2f05a
[skip style] [skip vbump] Restyle files
github-actions[bot] Oct 30, 2024
5b1e1a8
simplify teal_code extract as it reuses qenv extract
m7pr Oct 31, 2024
7fd89a1
Merge branch '211_subset@main' of https://github.com/insightsengineer…
m7pr Oct 31, 2024
a93b2d4
add .raw_data to names that need to be extracted
m7pr Nov 6, 2024
a0d4890
update teal.data constructor after changes in the code structure in q…
m7pr Nov 6, 2024
ee05635
use getFromNamespace instead of teal.code:::
m7pr Nov 6, 2024
84f8ceb
use code2list wrapper from teal.code
m7pr Nov 6, 2024
b465322
create code2list in teal.daata
m7pr Nov 6, 2024
d629a04
revert names to not add .raw_data
m7pr Nov 6, 2024
a8dd885
fix tests and improve [.teal_data
m7pr Nov 8, 2024
1121dc0
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 8, 2024
9aa4d94
Empty-Commit
m7pr Nov 8, 2024
0669e3e
bulletprove teal_data's code2list
m7pr Nov 8, 2024
98d6194
remove trimws
m7pr Nov 8, 2024
e31d65a
Merge remote-tracking branch 'origin/main' into 211_subset@main
gogonzo Nov 8, 2024
2b9da8e
postmerge fixes
gogonzo Nov 8, 2024
5c3bb7c
O M G
m7pr Nov 8, 2024
4900c3a
fix last test
m7pr Nov 8, 2024
0c5e677
fix
gogonzo Nov 8, 2024
159b6dd
fix tests
gogonzo Nov 8, 2024
a24bac3
fix for unverified
gogonzo Nov 8, 2024
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 @@ -72,10 +72,11 @@ Collate:
'join_keys.R'
'teal.data.R'
'teal_data-class.R'
'teal_data-constructor.R'
'teal_data-datanames.R'
'teal_data-extract.R'
'teal_data-get_code.R'
'teal_data-show.R'
'teal_data.R'
'testhat-helpers.R'
'topological_sort.R'
'verify.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method("[",join_keys)
S3method("[",teal_data)
S3method("[<-",join_keys)
S3method("[[<-",join_keys)
S3method("join_keys<-",join_keys)
Expand Down
3 changes: 3 additions & 0 deletions R/teal_data.R → R/teal_data-constructor.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#'
#' @export
#'
#' @name teal_data
#' @rdname teal_data
#'
m7pr marked this conversation as resolved.
Show resolved Hide resolved
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' @examples
#' teal_data(x1 = iris, x2 = mtcars)
#'
Expand Down
49 changes: 49 additions & 0 deletions R/teal_data-extract.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#'
#' @section Subsetting:
#' `x[names]` subsets objects in `teal_data` environment and limit the code to the necessary needed to build limited
#' objects.
#'
#' @param names (`character`) names of objects included in `teal_subset` to subset
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' @param x (`teal_data`)
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @examples
#'
#' # Subsetting
#' data <- teal_data()
#' data <- eval_code(data, "a <- 1;b<-2")
#' data["a"]
#' data[c("a", "b")]
#'
#' join_keys(data) <- join_keys(join_key("a", "b", "x"))
#' join_keys(data["a"]) # should show empty keys
#' join_keys(data["b"])
#' join_keys(data)["a"] # should show empty keys
#' join_keys(data)["b"]
#'
#' @rdname teal_data
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @export
`[.teal_data` <- function(x, names) {
checkmate::assert_class(names, "character")
m7pr marked this conversation as resolved.
Show resolved Hide resolved
names_in_env <- intersect(names, ls(get_env(x)))
if (!length(names_in_env)) {
return(teal_data())
}
# From ?NextMethod
# To pass `names` to `NextMethod` - it looks like it needs to be called `names`
# and created in the environment of the function that calls `NextMehod`.

# NextMethod works by creating a special call frame for the next method. If no new arguments are supplied, the
# arguments will be the same in number, order and name as those to the current method but their values will be
# promises to evaluate their name in the current method and environment. Any named arguments matched to ... are
# handled specially: they either replace existing arguments of the same name or are appended to the argument list.
# They are passed on as the promise that was supplied as an argument to the current environment.
# (S does this differently!) If they have been evaluated in the current (or a previous environment) they remain
# evaluated. (This is a complex area, and subject to change: see the draft ‘R Language Definition’.)

names <- names_in_env
x <- NextMethod("`[`", x)
m7pr marked this conversation as resolved.
Show resolved Hide resolved
x@join_keys <- x@join_keys[names_in_env]

x
}
28 changes: 27 additions & 1 deletion man/teal_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading