Skip to content

Commit 5fd964a

Browse files
authored
Merge pull request #11 from tidymodels/recipes-update
Recipes update
2 parents 5063906 + 67ad57e commit 5fd964a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+4858
-1122
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ before_install:
6969
- sudo apt-get -y install libnlopt-dev
7070
- sudo apt-get update
7171
- sudo apt-get -y install python3
72+
- mkdir -p ~/.R
73+
- echo "CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined" >> ~/.R/Makevars
74+
- echo "CXX14=g++ -std=c++1y -fPIC" >> ~/.R/Makevars
7275

7376
after_success:
7477
- Rscript -e 'covr::codecov()'
78+
- travis_wait 59 Rscript -e 'covr::coveralls(line_exclusions="src/init.cpp")'

DESCRIPTION

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Authors@R: c(
77
person("RStudio", role = "cph"))
88
Depends:
99
R (>= 3.1),
10-
recipes (>= 0.1.3)
10+
recipes (>= 0.1.3.9002)
1111
Imports:
1212
rstanarm,
1313
keras,
@@ -26,6 +26,8 @@ Suggests:
2626
knitr,
2727
rmarkdown,
2828
covr
29+
Remotes:
30+
tidymodels/recipes
2931
License: GPL-2
3032
Encoding: UTF-8
3133
LazyData: true
@@ -34,6 +36,3 @@ Roxygen: list(markdown = TRUE)
3436
ByteCompile: true
3537
URL: https://tidymodels.github.io/embed
3638
BugReports: https://github.com/tidymodels/embed/issues
37-
Remotes:
38-
r-lib/generics,
39-
tidymodels/recipes

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export(step_lencode_bayes)
2222
export(step_lencode_glm)
2323
export(step_lencode_mixed)
2424
export(tidy)
25+
export(tidy.step_embed)
26+
export(tidy.step_lencode_bayes)
27+
export(tidy.step_lencode_glm)
28+
export(tidy.step_lencode_mixed)
2529
import(rlang)
2630
importFrom(dplyr,"%>%")
2731
importFrom(dplyr,arrange)
@@ -57,6 +61,7 @@ importFrom(recipes,is_trained)
5761
importFrom(recipes,names0)
5862
importFrom(recipes,prep)
5963
importFrom(recipes,printer)
64+
importFrom(recipes,rand_id)
6065
importFrom(recipes,sel2char)
6166
importFrom(recipes,step)
6267
importFrom(recipes,terms_select)

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# `embed` 0.0.2
2+
3+
A mostly maintainence release to be compatible with version 0.1.3 of `recipes`.
4+
5+
## Other Changes:
6+
7+
* The package now depends on the `generics` pacakge to get the `broom` `tidy` methods.
8+
9+
* Karim Lahrichi added the ability to use callbacks when fitting tensorflow models. [PR](https://github.com/tidymodels/embed/pull/9)
10+
11+
112
# `embed` 0.0.1
213

314
First CRAN version

R/bayes.R

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#' the computations for subsequent operations
3131
#' @param trained A logical to indicate if the quantities for
3232
#' preprocessing have been estimated.
33+
#' @param id A character string that is unique to this step to identify it.
3334
#' @return An updated version of `recipe` with the new step added
3435
#' to the sequence of existing steps (if any). For the `tidy`
3536
#' method, a tibble with columns `terms` (the selectors or
@@ -93,7 +94,7 @@
9394
#'
9495
#' # See https://tidymodels.github.io/embed/ for examples
9596

96-
#' @importFrom recipes add_step step terms_select sel2char ellipse_check
97+
#' @importFrom recipes add_step step terms_select sel2char ellipse_check rand_id
9798
step_lencode_bayes <-
9899
function(recipe,
99100
...,
@@ -103,7 +104,8 @@ step_lencode_bayes <-
103104
options = list(seed = sample.int(10^5, 1)),
104105
verbose = FALSE,
105106
mapping = NULL,
106-
skip = FALSE) {
107+
skip = FALSE,
108+
id = rand_id("lencode_bayes")) {
107109
if (is.null(outcome))
108110
stop("Please list a variable in `outcome`", call. = FALSE)
109111
add_step(
@@ -116,20 +118,14 @@ step_lencode_bayes <-
116118
options = options,
117119
verbose = verbose,
118120
mapping = mapping,
119-
skip = skip
121+
skip = skip,
122+
id = id
120123
)
121124
)
122125
}
123126

124127
step_lencode_bayes_new <-
125-
function(terms = NULL,
126-
role = NA,
127-
trained = FALSE,
128-
outcome = NULL,
129-
options = NULL,
130-
verbose = FALSE,
131-
mapping = NULL,
132-
skip = FALSE) {
128+
function(terms, role, trained, outcome, options, verbose, mapping, skip, id) {
133129
step(
134130
subclass = "lencode_bayes",
135131
terms = terms,
@@ -139,7 +135,8 @@ step_lencode_bayes_new <-
139135
options = options,
140136
verbose = verbose,
141137
mapping = mapping,
142-
skip = skip
138+
skip = skip,
139+
id = id
143140
)
144141
}
145142

@@ -152,9 +149,17 @@ prep.step_lencode_bayes <- function(x, training, info = NULL, ...) {
152149
res <-
153150
map(training[, col_names], stan_coefs, y = training[, y_name],
154151
x$options, x$verbose)
155-
x$mapping <- res
156-
x$trained <- TRUE
157-
x
152+
step_lencode_bayes_new(
153+
terms = x$terms,
154+
role = x$role,
155+
trained = TRUE,
156+
outcome = x$outcome,
157+
options = x$options,
158+
verbose = x$verbose,
159+
mapping = res,
160+
skip = x$skip,
161+
id = x$id
162+
)
158163
}
159164

160165
#' @importFrom stats as.formula glm binomial coef gaussian na.omit
@@ -241,11 +246,11 @@ map_glm_coef <- function(dat, mapping) {
241246
#' @importFrom recipes bake prep
242247
#' @importFrom purrr map
243248
#' @export
244-
bake.step_lencode_bayes <- function(object, newdata, ...) {
249+
bake.step_lencode_bayes <- function(object, new_data, ...) {
245250
for (col in names(object$mapping))
246-
newdata[, col] <- map_glm_coef(newdata[, col], object$mapping[[col]])
251+
new_data[, col] <- map_glm_coef(new_data[, col], object$mapping[[col]])
247252

248-
newdata
253+
new_data
249254
}
250255

251256
#' @importFrom recipes printer
@@ -262,6 +267,7 @@ print.step_lencode_bayes <-
262267
#' @rdname step_lencode_bayes
263268
#' @param x A `step_lencode_bayes` object.
264269
#' @export
270+
#' @export tidy.step_lencode_bayes
265271
tidy.step_lencode_bayes <- function(x, ...) {
266272
if (is_trained(x)) {
267273
for(i in seq_along(x$mapping))
@@ -277,6 +283,7 @@ tidy.step_lencode_bayes <- function(x, ...) {
277283
terms = term_names
278284
)
279285
}
286+
res$id <- x$id
280287
res
281288
}
282289

R/glm.R

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#' the computations for subsequent operations
2727
#' @param trained A logical to indicate if the quantities for
2828
#' preprocessing have been estimated.
29+
#' @param id A character string that is unique to this step to identify it.
2930
#' @return An updated version of `recipe` with the new step added
3031
#' to the sequence of existing steps (if any). For the `tidy`
3132
#' method, a tibble with columns `terms` (the selectors or
@@ -74,7 +75,8 @@ step_lencode_glm <-
7475
trained = FALSE,
7576
outcome = NULL,
7677
mapping = NULL,
77-
skip = FALSE) {
78+
skip = FALSE,
79+
id = rand_id("lencode_bayes")) {
7880
if (is.null(outcome))
7981
stop("Please list a variable in `outcome`", call. = FALSE)
8082
add_step(
@@ -85,26 +87,23 @@ step_lencode_glm <-
8587
trained = trained,
8688
outcome = outcome,
8789
mapping = mapping,
88-
skip = skip
90+
skip = skip,
91+
id = id
8992
)
9093
)
9194
}
9295

9396
step_lencode_glm_new <-
94-
function(terms = NULL,
95-
role = NA,
96-
trained = FALSE,
97-
outcome = NULL,
98-
mapping = NULL,
99-
skip = FALSE) {
97+
function(terms, role, trained, outcome, mapping, skip, id) {
10098
step(
10199
subclass = "lencode_glm",
102100
terms = terms,
103101
role = role,
104102
trained = trained,
105103
outcome = outcome,
106104
mapping = mapping,
107-
skip = skip
105+
skip = skip,
106+
id = id
108107
)
109108
}
110109

@@ -115,9 +114,14 @@ prep.step_lencode_glm <- function(x, training, info = NULL, ...) {
115114
check_type(training[, col_names], quant = FALSE)
116115
y_name <- terms_select(x$outcome, info = info)
117116
res <- map(training[, col_names], glm_coefs, y = training[, y_name])
118-
x$mapping <- res
119-
x$trained <- TRUE
120-
x
117+
step_lencode_glm_new(
118+
terms = x$terms,
119+
role = x$role,
120+
trained = TRUE,
121+
outcome = x$outcome,
122+
mapping = res,
123+
skip = x$skip,
124+
id = x$id)
121125
}
122126

123127
#' @importFrom stats as.formula glm binomial coef gaussian na.omit
@@ -166,11 +170,11 @@ map_glm_coef <- function(dat, mapping) {
166170
#' @importFrom recipes bake prep
167171
#' @importFrom purrr map
168172
#' @export
169-
bake.step_lencode_glm <- function(object, newdata, ...) {
173+
bake.step_lencode_glm <- function(object, new_data, ...) {
170174
for (col in names(object$mapping))
171-
newdata[, col] <- map_glm_coef(newdata[, col], object$mapping[[col]])
175+
new_data[, col] <- map_glm_coef(new_data[, col], object$mapping[[col]])
172176

173-
newdata
177+
new_data
174178
}
175179

176180
#' @importFrom recipes printer
@@ -187,6 +191,7 @@ print.step_lencode_glm <-
187191
#' @rdname step_lencode_glm
188192
#' @param x A `step_lencode_glm` object.
189193
#' @export
194+
#' @export tidy.step_lencode_glm
190195
tidy.step_lencode_glm <- function(x, ...) {
191196
if (is_trained(x)) {
192197
for(i in seq_along(x$mapping))
@@ -202,6 +207,7 @@ tidy.step_lencode_glm <- function(x, ...) {
202207
terms = term_names
203208
)
204209
}
210+
res$id <- x$id
205211
res
206212
}
207213

R/lme.R

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#' the computations for subsequent operations
2929
#' @param trained A logical to indicate if the quantities for
3030
#' preprocessing have been estimated.
31+
#' @param id A character string that is unique to this step to identify it.
3132
#' @return An updated version of `recipe` with the new step added
3233
#' to the sequence of existing steps (if any). For the `tidy`
3334
#' method, a tibble with columns `terms` (the selectors or
@@ -90,7 +91,8 @@ step_lencode_mixed <-
9091
outcome = NULL,
9192
options = list(verbose = 0),
9293
mapping = NULL,
93-
skip = FALSE) {
94+
skip = FALSE,
95+
id = rand_id("lencode_bayes")) {
9496
if (is.null(outcome))
9597
stop("Please list a variable in `outcome`", call. = FALSE)
9698
add_step(
@@ -102,19 +104,14 @@ step_lencode_mixed <-
102104
outcome = outcome,
103105
options = options,
104106
mapping = mapping,
105-
skip = skip
107+
skip = skip,
108+
id = id
106109
)
107110
)
108111
}
109112

110113
step_lencode_mixed_new <-
111-
function(terms = NULL,
112-
role = NA,
113-
trained = FALSE,
114-
outcome = NULL,
115-
options = NULL,
116-
mapping = NULL,
117-
skip = FALSE) {
114+
function(terms, role, trained, outcome, options, mapping, skip, id) {
118115
step(
119116
subclass = "lencode_mixed",
120117
terms = terms,
@@ -123,7 +120,8 @@ step_lencode_mixed_new <-
123120
outcome = outcome,
124121
options = options,
125122
mapping = mapping,
126-
skip = skip
123+
skip = skip,
124+
id = id
127125
)
128126
}
129127

@@ -143,9 +141,16 @@ prep.step_lencode_mixed <- function(x, training, info = NULL, ...) {
143141
res <-
144142
map(training[, col_names], lme_coefs, y = training[[y_name]],
145143
x$options)
146-
x$mapping <- res
147-
x$trained <- TRUE
148-
x
144+
step_lencode_mixed_new(
145+
terms = x$terms,
146+
role = x$role,
147+
trained = TRUE,
148+
outcome = x$outcome,
149+
options = x$options,
150+
mapping = res,
151+
skip = x$skip,
152+
id = x$id
153+
)
149154
}
150155

151156
#' @importFrom stats as.formula binomial coef gaussian na.omit
@@ -204,11 +209,11 @@ map_lme_coef <- function(dat, mapping) {
204209
#' @importFrom recipes bake prep
205210
#' @importFrom purrr map
206211
#' @export
207-
bake.step_lencode_mixed <- function(object, newdata, ...) {
212+
bake.step_lencode_mixed <- function(object, new_data, ...) {
208213
for (col in names(object$mapping))
209-
newdata[, col] <- map_lme_coef(newdata[, col], object$mapping[[col]])
214+
new_data[, col] <- map_lme_coef(new_data[, col], object$mapping[[col]])
210215

211-
newdata
216+
new_data
212217
}
213218

214219
#' @importFrom recipes printer
@@ -225,6 +230,7 @@ print.step_lencode_mixed <-
225230
#' @rdname step_lencode_mixed
226231
#' @param x A `step_lencode_mixed` object.
227232
#' @export
233+
#' @export tidy.step_lencode_mixed
228234
tidy.step_lencode_mixed <- function(x, ...) {
229235
if (is_trained(x)) {
230236
for(i in seq_along(x$mapping))
@@ -240,6 +246,7 @@ tidy.step_lencode_mixed <- function(x, ...) {
240246
terms = term_names
241247
)
242248
}
249+
res$id <- x$id
243250
res
244251
}
245252

0 commit comments

Comments
 (0)