diff --git a/DESCRIPTION b/DESCRIPTION index 7c2e6ce..5eeca9b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: modeldb Title: Fits Models Inside the Database -Version: 0.3.0.9000 +Version: 0.3.1 Authors@R: c( person("Edgar", "Ruiz", , "edgar@posit.co", role = "aut"), person("Max", "Kuhn", , "max@posit.co", role = c("aut", "cre")) @@ -38,4 +38,4 @@ Config/Needs/website: tidyverse/tidytemplate Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 diff --git a/NEWS.md b/NEWS.md index 962798a..fb6b140 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,6 @@ -# modeldb (development version) +# modeldb 0.3.1 + +- Fixes compatability issues with `ggplot2` # modeldb 0.3.0 diff --git a/README.Rmd b/README.Rmd index d29b83c..8304019 100644 --- a/README.Rmd +++ b/README.Rmd @@ -79,7 +79,7 @@ dbplyr::remote_query(km) This project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. -- For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on Posit Community](https://community.rstudio.com/new-topic?category_id=15&tags=tidymodels,question). +- For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on Posit Community](https://forum.posit.co/new-topic?category_id=15&tags=tidymodels,question). - If you think you have encountered a bug, please [submit an issue](https://github.com/tidymodels/modeldb/issues). diff --git a/README.md b/README.md index 7eea69b..6d9d707 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ back-ends** because it leverages [dplyr](https://dplyr.tidyverse.org/) and [dbplyr](https://dbplyr.tidyverse.org/) for the final SQL translation of the algorithm. It currently supports: -- K-means clustering +- K-means clustering -- Linear regression +- Linear regression ## Installation @@ -66,8 +66,8 @@ To use the `simple_kmeans_db()` function, simply pipe the database back end table to the function. This returns a list object that contains two items: -- A sql query table with the final center assignment -- A local table with the information about the centers +- A sql query table with the final center assignment +- A local table with the information about the centers ``` r km <- tbl(con, "mtcars") %>% @@ -87,31 +87,80 @@ The SQL statement from `tbl` can be extracted using dbplyr’s dbplyr::remote_query(km) ``` - ## SELECT `k_center`, `k_mpg`, `k_wt`, `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb` - ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `LHS`.`k_center` AS `k_center`, `k_mpg`, `k_wt` - ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center` AS `k_center` - ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center_1`, `center_2`, `center_3`, CASE - ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN ('center_1') - ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN ('center_2') - ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN ('center_3') + ## SELECT + ## `LHS`.`k_center` AS `k_center`, + ## `k_mpg`, + ## `k_wt`, + ## `mpg`, + ## `cyl`, + ## `disp`, + ## `hp`, + ## `drat`, + ## `wt`, + ## `qsec`, + ## `vs`, + ## `am`, + ## `gear`, + ## `carb` + ## FROM ( + ## SELECT + ## `mpg`, + ## `cyl`, + ## `disp`, + ## `hp`, + ## `drat`, + ## `wt`, + ## `qsec`, + ## `vs`, + ## `am`, + ## `gear`, + ## `carb`, + ## `center` AS `k_center` + ## FROM ( + ## SELECT + ## `q01`.*, + ## CASE + ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN 'center_1' + ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN 'center_2' + ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN 'center_3' ## END AS `center` - ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`, SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`, SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3` - ## FROM `mtcars`)) - ## WHERE (NOT(((`center`) IS NULL)))) AS `LHS` - ## LEFT JOIN (SELECT `center` AS `k_center`, `mpg` AS `k_mpg`, `wt` AS `k_wt` - ## FROM (SELECT `center`, AVG(`mpg`) AS `mpg`, AVG(`wt`) AS `wt` - ## FROM (SELECT `mpg`, `wt`, `center` - ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, `center_1`, `center_2`, `center_3`, CASE - ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN ('center_1') - ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN ('center_2') - ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN ('center_3') + ## FROM ( + ## SELECT + ## `mtcars`.*, + ## SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`, + ## SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`, + ## SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3` + ## FROM `mtcars` + ## ) AS `q01` + ## ) AS `q01` + ## WHERE (NOT((`center` IS NULL))) + ## ) AS `LHS` + ## LEFT JOIN ( + ## SELECT `center` AS `k_center`, AVG(`mpg`) AS `k_mpg`, AVG(`wt`) AS `k_wt` + ## FROM ( + ## SELECT `mpg`, `wt`, `center` + ## FROM ( + ## SELECT + ## `q01`.*, + ## CASE + ## WHEN (`center_1` >= `center_1` AND `center_1` < `center_2` AND `center_1` < `center_3`) THEN 'center_1' + ## WHEN (`center_2` < `center_1` AND `center_2` >= `center_2` AND `center_2` < `center_3`) THEN 'center_2' + ## WHEN (`center_3` < `center_1` AND `center_3` < `center_2` AND `center_3` >= `center_3`) THEN 'center_3' ## END AS `center` - ## FROM (SELECT `mpg`, `cyl`, `disp`, `hp`, `drat`, `wt`, `qsec`, `vs`, `am`, `gear`, `carb`, SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`, SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`, SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3` - ## FROM `mtcars`)) - ## WHERE (NOT(((`center`) IS NULL)))) - ## GROUP BY `center`)) AS `RHS` - ## ON (`LHS`.`k_center` = `RHS`.`k_center`) - ## ) + ## FROM ( + ## SELECT + ## `mtcars`.*, + ## SQRT(((20.6428571428571 - `mpg`) * (20.6428571428571 - `mpg`)) + ((3.07214285714286 - `wt`) * (3.07214285714286 - `wt`))) AS `center_1`, + ## SQRT(((14.4583333333333 - `mpg`) * (14.4583333333333 - `mpg`)) + ((4.05866666666667 - `wt`) * (4.05866666666667 - `wt`))) AS `center_2`, + ## SQRT(((30.0666666666667 - `mpg`) * (30.0666666666667 - `mpg`)) + ((1.873 - `wt`) * (1.873 - `wt`))) AS `center_3` + ## FROM `mtcars` + ## ) AS `q01` + ## ) AS `q01` + ## WHERE (NOT((`center` IS NULL))) + ## ) AS `q01` + ## GROUP BY `center` + ## ) AS `RHS` + ## ON (`LHS`.`k_center` = `RHS`.`k_center`) ## Contributing @@ -119,20 +168,20 @@ This project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. -- For questions and discussions about tidymodels packages, modeling, - and machine learning, please [post on Posit - Community](https://community.rstudio.com/new-topic?category_id=15&tags=tidymodels,question). +- For questions and discussions about tidymodels packages, modeling, and + machine learning, please [post on Posit + Community](https://forum.posit.co/new-topic?category_id=15&tags=tidymodels,question). -- If you think you have encountered a bug, please [submit an - issue](https://github.com/tidymodels/modeldb/issues). +- If you think you have encountered a bug, please [submit an + issue](https://github.com/tidymodels/modeldb/issues). -- Either way, learn how to create and share a - [reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html) - (a minimal, reproducible example), to clearly communicate about your - code. Check out [this helpful article on how to create - reprexes](https://dbplyr.tidyverse.org/articles/reprex.html) for - problems involving a database. +- Either way, learn how to create and share a + [reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html) + (a minimal, reproducible example), to clearly communicate about your + code. Check out [this helpful article on how to create + reprexes](https://dbplyr.tidyverse.org/articles/reprex.html) for + problems involving a database. -- Check out further details on [contributing guidelines for tidymodels - packages](https://www.tidymodels.org/contribute/) and [how to get - help](https://www.tidymodels.org/help/). +- Check out further details on [contributing guidelines for tidymodels + packages](https://www.tidymodels.org/contribute/) and [how to get + help](https://www.tidymodels.org/help/). diff --git a/man/modeldb-package.Rd b/man/modeldb-package.Rd index 62e2711..5dffc1d 100644 --- a/man/modeldb-package.Rd +++ b/man/modeldb-package.Rd @@ -22,5 +22,10 @@ Useful links: \author{ \strong{Maintainer}: Max Kuhn \email{max@posit.co} +Authors: +\itemize{ + \item Edgar Ruiz \email{edgar@posit.co} +} + } \keyword{internal} diff --git a/tests/testthat/test-as-parsed-model.R b/tests/testthat/test-as-parsed-model.R index 66ac255..54d251a 100644 --- a/tests/testthat/test-as-parsed-model.R +++ b/tests/testthat/test-as-parsed-model.R @@ -1,5 +1,3 @@ -context("parsed model") - test_that("Simple linear regression matches lm()", { expect_is( as_parsed_model( diff --git a/tests/testthat/test_dummy_var.R b/tests/testthat/test_dummy_var.R index 9a81ca8..24746ea 100644 --- a/tests/testthat/test_dummy_var.R +++ b/tests/testthat/test_dummy_var.R @@ -1,5 +1,3 @@ -context("add_dummy_variables") - test_that("Function create the correct columns", { cols_expected <- c("mpg", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear", "carb", "cyl_6", "cyl_8") expect_equal( diff --git a/tests/testthat/test_kmeans.R b/tests/testthat/test_kmeans.R index 7fc7e01..63144a5 100644 --- a/tests/testthat/test_kmeans.R +++ b/tests/testthat/test_kmeans.R @@ -1,5 +1,3 @@ -context("kmeans") - test_that("Specifying variables works", { expect_is( simple_kmeans_db(mtcars, wt, mpg), diff --git a/tests/testthat/test_kmeans_viz.R b/tests/testthat/test_kmeans_viz.R index 320f4b7..451bf7c 100644 --- a/tests/testthat/test_kmeans_viz.R +++ b/tests/testthat/test_kmeans_viz.R @@ -1,10 +1,7 @@ -context("kmeans_viz") - test_that("plot_kmeans() returns a ggplot2 object", { - expect_equal( - class(plot_kmeans(mtcars, mpg, wt, group = am)), - c("gg", "ggplot") + expect_true( + inherits(plot_kmeans(mtcars, mpg, wt, group = am), "ggplot") ) }) diff --git a/tests/testthat/test_lr.R b/tests/testthat/test_lr.R index 460d9a3..046484b 100644 --- a/tests/testthat/test_lr.R +++ b/tests/testthat/test_lr.R @@ -1,5 +1,3 @@ -context("Linear Regression") - test_that("Simple linear regression matches lm()", { expect_equal( lm(wt ~ mpg, data = mtcars) %>%