From 2235dd44e14906e9798f49fcba8a85099b0b3664 Mon Sep 17 00:00:00 2001 From: topepo Date: Fri, 2 Aug 2019 10:34:32 -0400 Subject: [PATCH 1/5] print out the testing environment --- tests/testthat/test_aaaa.R | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_aaaa.R b/tests/testthat/test_aaaa.R index 4bc446c0c..cf5e397f4 100644 --- a/tests/testthat/test_aaaa.R +++ b/tests/testthat/test_aaaa.R @@ -4,7 +4,41 @@ library(testthat) -context("setting keras environment\n") +context("setting keras environment") Sys.setenv(TF_CPP_MIN_LOG_LEVEL = '3') -try(keras:::backend(), silent = TRUE) +k_bk <- try(keras:::backend(), silent = TRUE) + +## ----------------------------------------------------------------------------- + +context("checking testing environment") + +cat("testing environment:\n") + +print(capabilities()) + +lps <- .libPaths() +cat("Library paths:\n") +print(lps) + +if (!inherits(k_bk, "try-error")) { + cat("keras backend:\n") + print(k_bk$tensorflow_backend) +} + +installed <- lapply(lps, function(x) rownames(installed.packages(x))) + +has_rstanarm <- lapply(installed, function(x) any(x == "rstanarm")) +if (any(unlist(has_rstanarm))) { + cat("rstanarm installed in:" , + paste0(lps[unlist(has_rstanarm)], collapse = ", "), + "\n") +} else { + cat("rstanarm not installed\n") +} + + + + + + From bdc0d288caa7fa7995998af656437dcf424720c5 Mon Sep 17 00:00:00 2001 From: topepo Date: Fri, 2 Aug 2019 12:41:01 -0400 Subject: [PATCH 2/5] less keras messages about setup --- tests/testthat/test_aaaa.R | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/testthat/test_aaaa.R b/tests/testthat/test_aaaa.R index cf5e397f4..34509fd94 100644 --- a/tests/testthat/test_aaaa.R +++ b/tests/testthat/test_aaaa.R @@ -21,11 +21,6 @@ lps <- .libPaths() cat("Library paths:\n") print(lps) -if (!inherits(k_bk, "try-error")) { - cat("keras backend:\n") - print(k_bk$tensorflow_backend) -} - installed <- lapply(lps, function(x) rownames(installed.packages(x))) has_rstanarm <- lapply(installed, function(x) any(x == "rstanarm")) From 859f2b2f0b3b35360bef9438ac86823fb6e1d6f3 Mon Sep 17 00:00:00 2001 From: topepo Date: Fri, 2 Aug 2019 13:12:40 -0400 Subject: [PATCH 3/5] testing out printing to stderr --- tests/testthat/test_aaaa.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test_aaaa.R b/tests/testthat/test_aaaa.R index 34509fd94..2fa8cf8ed 100644 --- a/tests/testthat/test_aaaa.R +++ b/tests/testthat/test_aaaa.R @@ -13,12 +13,12 @@ k_bk <- try(keras:::backend(), silent = TRUE) context("checking testing environment") -cat("testing environment:\n") +cat("testing environment:\n", file = stderr()) print(capabilities()) lps <- .libPaths() -cat("Library paths:\n") +cat("Library paths:\n", file = stderr()) print(lps) installed <- lapply(lps, function(x) rownames(installed.packages(x))) @@ -27,9 +27,10 @@ has_rstanarm <- lapply(installed, function(x) any(x == "rstanarm")) if (any(unlist(has_rstanarm))) { cat("rstanarm installed in:" , paste0(lps[unlist(has_rstanarm)], collapse = ", "), - "\n") + "\n", + file = stderr()) } else { - cat("rstanarm not installed\n") + cat("rstanarm not installed\n", file = stderr()) } From f809234b5113cdd652761060fab388de1c66e757 Mon Sep 17 00:00:00 2001 From: topepo Date: Fri, 2 Aug 2019 16:23:13 -0400 Subject: [PATCH 4/5] better handling of unknown modes --- R/fit.R | 4 ++++ tests/testthat/test_fit_interfaces.R | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/R/fit.R b/R/fit.R index 1cb32f300..67a2f2e9a 100644 --- a/R/fit.R +++ b/R/fit.R @@ -94,6 +94,9 @@ fit.model_spec <- control = fit_control(), ... ) { + if (object$mode == "unknown") { + stop("Please set the mode in the model specification.", call. = FALSE) + } dots <- quos(...) if (is.null(object$engine)) { eng_vals <- possible_engines(object) @@ -183,6 +186,7 @@ fit_xy.model_spec <- control = fit_control(), ... ) { + object <- check_mode(object, levels(y)) dots <- quos(...) if (is.null(object$engine)) { eng_vals <- possible_engines(object) diff --git a/tests/testthat/test_fit_interfaces.R b/tests/testthat/test_fit_interfaces.R index c06a8b537..be0ae9597 100644 --- a/tests/testthat/test_fit_interfaces.R +++ b/tests/testthat/test_fit_interfaces.R @@ -60,3 +60,22 @@ test_that('single column df for issue #129', { expect_equal(coef(lm1), coef(lm3)) expect_equal(coef(lm2), coef(lm3)) }) + +# ------------------------------------------------------------------------------ + +test_that('unknown modes', { + mars_spec <- set_engine(mars(), "earth") + expect_error( + fit(mars_spec, am ~ ., data = mtcars), + "Please set the mode in the model specification." + ) + expect_error( + fit_xy(mars_spec, x = mtcars[, -1], y = mtcars[,1]), + regexp = NA + ) + expect_error( + fit_xy(mars_spec, x = lending_club[,1:2], y = lending_club$Class), + regexp = NA + ) +}) + From d2675cdee090212115e78ea0b8e977c84f69768d Mon Sep 17 00:00:00 2001 From: topepo Date: Mon, 5 Aug 2019 21:10:05 -0400 Subject: [PATCH 5/5] version sent to cran --- DESCRIPTION | 6 ++--- NEWS.md | 5 ++++- tests/testthat/test_aaaa.R | 30 ------------------------- tests/testthat/test_linear_reg_stan.R | 11 +++++---- tests/testthat/test_logistic_reg_stan.R | 4 ++++ 5 files changed, 18 insertions(+), 38 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d9c46830b..8ff97c42a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,10 @@ Package: parsnip -Version: 0.0.3.9000 +Version: 0.0.3.1 Title: A Common API to Modeling and Analysis Functions Description: A common interface is provided to allow users to specify a model without having to remember the different argument names across different functions or computational engines (e.g. 'R', 'Spark', 'Stan', etc). Authors@R: c( - person("Max", "Kuhn", , "max@rstudio.com", c("aut", "cre")), - person("Davis", "Vaughan", , "davis@rstudio.com", c("aut")), + person(given = "Max", family = "Kuhn", email = "max@rstudio.com", role = c("aut", "cre")), + person(given = "Davis", family = "Vaughan", email = "davis@rstudio.com", role = c("aut")), person("RStudio", role = "cph")) Maintainer: Max Kuhn URL: https://tidymodels.github.io/parsnip diff --git a/NEWS.md b/NEWS.md index 024f4f38d..b125323ca 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,7 @@ -# parsnip 0.0.3.9000 +# parsnip 0.0.3.1 + +Test case update due to CRAN running extra tests [(#202)](https://github.com/tidymodels/parsnip/issues/202) + # parsnip 0.0.3 diff --git a/tests/testthat/test_aaaa.R b/tests/testthat/test_aaaa.R index 2fa8cf8ed..78ae245aa 100644 --- a/tests/testthat/test_aaaa.R +++ b/tests/testthat/test_aaaa.R @@ -8,33 +8,3 @@ context("setting keras environment") Sys.setenv(TF_CPP_MIN_LOG_LEVEL = '3') k_bk <- try(keras:::backend(), silent = TRUE) - -## ----------------------------------------------------------------------------- - -context("checking testing environment") - -cat("testing environment:\n", file = stderr()) - -print(capabilities()) - -lps <- .libPaths() -cat("Library paths:\n", file = stderr()) -print(lps) - -installed <- lapply(lps, function(x) rownames(installed.packages(x))) - -has_rstanarm <- lapply(installed, function(x) any(x == "rstanarm")) -if (any(unlist(has_rstanarm))) { - cat("rstanarm installed in:" , - paste0(lps[unlist(has_rstanarm)], collapse = ", "), - "\n", - file = stderr()) -} else { - cat("rstanarm not installed\n", file = stderr()) -} - - - - - - diff --git a/tests/testthat/test_linear_reg_stan.R b/tests/testthat/test_linear_reg_stan.R index d628fa443..012e73539 100644 --- a/tests/testthat/test_linear_reg_stan.R +++ b/tests/testthat/test_linear_reg_stan.R @@ -19,6 +19,7 @@ quiet_ctrl <- fit_control(verbosity = 0L, catch = TRUE) test_that('stan_glm execution', { skip_if_not_installed("rstanarm") + skip_on_cran() expect_error( res <- fit( @@ -56,6 +57,7 @@ test_that('stan_glm execution', { test_that('stan prediction', { skip_if_not_installed("rstanarm") + skip_on_cran() uni_pred <- c(5.01531691055198, 4.6896592504705, 4.74907435900005, 4.82563873798984, 5.08044844256827) @@ -84,6 +86,7 @@ test_that('stan prediction', { test_that('stan intervals', { skip_if_not_installed("rstanarm") + skip_on_cran() res_xy <- fit_xy( linear_reg() %>% @@ -115,15 +118,15 @@ test_that('stan intervals', { pi_upper <- c(5.59783267637042, 5.25976504318669, 5.33296516452929, 5.41050668003565, 5.66355828140989) - expect_equivalent(confidence_parsnip$.pred_lower, ci_lower) - expect_equivalent(confidence_parsnip$.pred_upper, ci_upper) + expect_equivalent(confidence_parsnip$.pred_lower, ci_lower, tolerance = 1e-2) + expect_equivalent(confidence_parsnip$.pred_upper, ci_upper, tolerance = 1e-2) expect_equivalent(prediction_parsnip$.pred_lower, pi_lower, - tol = 0.01) + tolerance = 1e-2) expect_equivalent(prediction_parsnip$.pred_upper, pi_upper, - tol = 0.01) + tolerance = 1e-2) }) diff --git a/tests/testthat/test_logistic_reg_stan.R b/tests/testthat/test_logistic_reg_stan.R index 18940994c..8a0f204e9 100644 --- a/tests/testthat/test_logistic_reg_stan.R +++ b/tests/testthat/test_logistic_reg_stan.R @@ -23,6 +23,7 @@ quiet_ctrl <- fit_control(verbosity = 0, catch = TRUE) test_that('stan_glm execution', { skip_if_not_installed("rstanarm") + skip_on_cran() expect_error( res <- fit( @@ -47,6 +48,7 @@ test_that('stan_glm execution', { test_that('stan_glm prediction', { skip_if_not_installed("rstanarm") + skip_on_cran() xy_fit <- fit_xy( logistic_reg() %>% @@ -80,6 +82,7 @@ test_that('stan_glm prediction', { test_that('stan_glm probability', { skip_if_not_installed("rstanarm") + skip_on_cran() xy_fit <- fit_xy( logistic_reg() %>% @@ -135,6 +138,7 @@ test_that('stan_glm probability', { test_that('stan intervals', { skip_if_not_installed("rstanarm") + skip_on_cran() res_form <- fit( logistic_reg() %>%