Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: trending
Title: Model Temporal Trends
Version: 0.1.0
Version: 0.1.0.9000
Authors@R:
c(
person(
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# trending (development version)

* Fix a bug in `fit.list()` that was causing it to sometimes fail when used
within other functions.

# trending 0.1.0

## Breaking changes
Expand Down
19 changes: 16 additions & 3 deletions R/fit-list.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,22 @@ fit.list <- function(x, data, ...) {
if (!all(vapply(x, inherits, logical(1), "trending_model"))) {
stop("list entries should be `trending_model` objects", call. = FALSE)
}
qfun <- bquote(lapply(x, fit, data = .(substitute(data)), as_tibble = FALSE))
res <- eval(qfun)
nms <- names(x)

# Fix for https://github.com/reconverse/trending/issues/22
# TODO - improve this as very, very hacky
original___x <- x
tmp <- as.character(substitute(data))
if (length(tmp) == 1L) {
assign(tmp[1L], data)
}
res <- vector("list", length(original___x))
for (i in seq_along(res)) {
x_model <- original___x[[i]]
qfun <- bquote(fit(x_model, data = .(substitute(data)), as_tibble = FALSE))
res[[i]] <- eval(qfun)
}
nms <- names(original___x)

if (!is.null(nms)) names(res) <- nms
res <- lapply(seq_along(res[[1]]), function(i) lapply(res, "[[", i))
res <- tibble(result = res[[1]], warnings = res[[2]], errors = res[[3]])
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-lists.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ test_that("lm_model", {
list_pred_nmd <- predict(list_fit_nmd, mtcars)
list_pred_from_model <- predict(list(l=l, nb=nb), mtcars)

# test for #22 fix
f <- function(y) fit(list(l, nb), y)
expect_identical(f(mtcars)$errors, list(NULL, NULL))


expect_equal(get_warnings(list_fit), list(NULL, NULL))
expect_equal(get_warnings(list_pred_from_model), list(l=NULL, nb=NULL))
expect_equal(get_errors(list_fit), list(NULL, NULL))
Expand Down