Skip to content

Commit ac10fd6

Browse files
committed
removed dictionary_cast
1 parent 03b7d09 commit ac10fd6

File tree

5 files changed

+0
-98
lines changed

5 files changed

+0
-98
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export(chunk_vector)
2626
export(compute_mode)
2727
export(cross_join)
2828
export(detect)
29-
export(dictionary_cast)
3029
export(dictionary_sugar)
3130
export(did_you_mean)
3231
export(discard)

NEWS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
* New function `detect()`.
66
* New function `dictionary_sugar()`.
7-
* New function `dictionary_cast()` (moved from `mlr3`).
87
* It is now asserted that the return value of Dictionaries is an R6 object.
98
* Fix some more assertions in `Dictionary`
109

R/dictionary_sugar.R

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -83,55 +83,3 @@ get_constructor_formals = function(x) {
8383

8484
return(character())
8585
}
86-
87-
88-
#' @title Cast Objects Using a Dictionary
89-
#'
90-
#' @description
91-
#' Uses a dictionary to cast objects of a specific type of a [Dictionary].
92-
#' Intended for package developers.
93-
#'
94-
#' @param `x` :: (`character()` | `list()`)\cr
95-
#' Object to cast.
96-
#' @param `type` :: `character(1)`\cr
97-
#' Expected type of objects.
98-
#' @param `dict` :: [Dictionary]\cr
99-
#' Expected type of objects.
100-
#' @param `clone` :: `logical(1)`\cr
101-
#' Clone objects, if necessary. Default is `FALSE`.
102-
#' @param `multiple` :: `logical(1)`\cr
103-
#' Cast multiple objects of type `type` or just a single one?
104-
#'
105-
#' @return Object of type `type` or list of objects of type `type`.
106-
#' @keywords internal
107-
#' @export
108-
dictionary_cast = function(dict, x, type, clone = FALSE, multiple = TRUE) {
109-
if (inherits(x, type)) {
110-
if (clone) {
111-
x = x$clone(deep = TRUE)
112-
}
113-
return(list(x))
114-
}
115-
116-
if (!is.character(x) && !is.list(x)) {
117-
stopf("Argument %s must be an object of type '%2$s', a list of elements of type '%2$s' or a character vector of keys to lookup in the dictionary",
118-
deparse(substitute(x)), type)
119-
}
120-
121-
if (!multiple && length(x) != 1L) {
122-
stopf("Argument %s must be an object of type '%2$s', a list with one element of type '%2$s' or a single key to lookup in the dictionary",
123-
deparse(substitute(x)), type)
124-
}
125-
126-
map(x, function(xi) {
127-
if (inherits(xi, type)) {
128-
return(if (clone) xi$clone(deep = TRUE) else xi)
129-
}
130-
if (is.character(xi) && length(xi) == 1L) {
131-
return(dict$get(xi))
132-
}
133-
134-
stopf("Argument %s must be an object of type '%2$s', a list of elements of type '%2$s' or a character vector of keys to lookup in the dictionary",
135-
deparse(substitute(x)), type)
136-
})
137-
}

man/dictionary_cast.Rd

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/testthat/test_Dictionary.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,6 @@ test_that("Dictionary throws exception on unnamed args", {
4747
expect_error(x$mget("a", "b"), "names")
4848
})
4949

50-
test_that("dictionary_cast", {
51-
Foo = R6::R6Class("Foo", public = list(x = 0), cloneable = TRUE)
52-
d = Dictionary$new()
53-
d$add("f1", Foo)
54-
55-
expect_list(dictionary_cast(d, "f1", "Foo"), "Foo", len = 1)
56-
expect_list(dictionary_cast(d, Foo$new(), "Foo"), len = 1)
57-
expect_list(dictionary_cast(d, c("f1", "f1"), "Foo"), "Foo", len = 2)
58-
expect_list(dictionary_cast(d, list("f1", "f1"), "Foo"), "Foo", len = 2)
59-
expect_list(dictionary_cast(d, list("f1", Foo$new()), "Foo"), "Foo", len = 2)
60-
})
61-
6250
test_that("dictionary_sugar", {
6351
Foo = R6::R6Class("Foo", public = list(x = 0, y = 0, key = 0, initialize = function(y, key = -1) { self$y = y ; self$key = key }), cloneable = TRUE)
6452
d = Dictionary$new()

0 commit comments

Comments
 (0)