From 50aa106978aa834a48158ce6cc263d4840c04521 Mon Sep 17 00:00:00 2001 From: Max Kuhn Date: Tue, 28 Jul 2020 17:18:11 -0400 Subject: [PATCH 1/2] added glance method for #325 --- DESCRIPTION | 2 +- NAMESPACE | 3 +++ NEWS.md | 2 ++ R/reexports.R | 5 +++++ R/tidy.R | 11 +++++++++++ R/zzz.R | 1 + man/glance.model_fit.Rd | 19 +++++++++++++++++++ man/reexports.Rd | 3 ++- 8 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 man/glance.model_fit.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 3262bb8d2..fc01bdfd5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,7 @@ Imports: prettyunits, vctrs (>= 0.2.0) Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.0.9000 +RoxygenNote: 7.1.1 Suggests: testthat, knitr, diff --git a/NAMESPACE b/NAMESPACE index 76443092d..d33da2365 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ S3method(fit,model_spec) S3method(fit_xy,model_spec) +S3method(glance,model_fit) S3method(has_multi_predict,default) S3method(has_multi_predict,model_fit) S3method(has_multi_predict,workflow) @@ -121,6 +122,7 @@ export(get_fit) export(get_from_env) export(get_model_env) export(get_pred_type) +export(glance) export(has_multi_predict) export(is_varying) export(keras_mlp) @@ -198,6 +200,7 @@ importFrom(dplyr,tally) importFrom(dplyr,vars) importFrom(generics,fit) importFrom(generics,fit_xy) +importFrom(generics,glance) importFrom(generics,tidy) importFrom(generics,varying_args) importFrom(glue,glue_collapse) diff --git a/NEWS.md b/NEWS.md index 56285ba2a..84a485f51 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # parsnip (development version) + * A `glance()` method for `model_fit` objects was added (#325) + * Specific `tidy()` methods for `glmnet` models fit via `parsnip` were created so that the coefficients for the specific fitted `parsnip` model are returned. # parsnip 0.1.2 diff --git a/R/reexports.R b/R/reexports.R index cee0a1581..f99dd38d2 100644 --- a/R/reexports.R +++ b/R/reexports.R @@ -14,3 +14,8 @@ generics::fit_xy #' @importFrom generics tidy #' @export generics::tidy + + +#' @importFrom generics glance +#' @export +generics::glance diff --git a/R/tidy.R b/R/tidy.R index ce5d4df91..64047a787 100644 --- a/R/tidy.R +++ b/R/tidy.R @@ -7,3 +7,14 @@ #' @return a tibble #' @export tidy.model_fit <- function(x, ...) generics::tidy(x$fit, ...) + + +#' Construct a single row summary "glance" of a model, fit, or other object +#' +#' This method glances the model in a parsnip model object, if it exists. +#' +#' @inheritParams generics::glance +#' +#' @return a tibble +#' @export +glance.model_fit <- function(x, ...) generics::glance(x$fit, ...) diff --git a/R/zzz.R b/R/zzz.R index 38b892186..17943665c 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -7,6 +7,7 @@ s3_register("broom::tidy", "_lognet") s3_register("broom::tidy", "_multnet") s3_register("broom::tidy", "_fishnet") + s3_register("broom::glance", "model_fit") } diff --git a/man/glance.model_fit.Rd b/man/glance.model_fit.Rd new file mode 100644 index 000000000..934bc8b25 --- /dev/null +++ b/man/glance.model_fit.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tidy.R +\name{glance.model_fit} +\alias{glance.model_fit} +\title{Construct a single row summary "glance" of a model, fit, or other object} +\usage{ +\method{glance}{model_fit}(x, ...) +} +\arguments{ +\item{x}{model or other R object to convert to single-row data frame} + +\item{...}{other arguments passed to methods} +} +\value{ +a tibble +} +\description{ +This method glances the model in a parsnip model object, if it exists. +} diff --git a/man/reexports.Rd b/man/reexports.Rd index 336c37348..97b2f3b2a 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -7,6 +7,7 @@ \alias{fit} \alias{fit_xy} \alias{tidy} +\alias{glance} \alias{varying_args} \title{Objects exported from other packages} \keyword{internal} @@ -15,7 +16,7 @@ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ - \item{generics}{\code{\link[generics]{fit}}, \code{\link[generics]{fit_xy}}, \code{\link[generics]{tidy}}, \code{\link[generics]{varying_args}}} + \item{generics}{\code{\link[generics]{fit}}, \code{\link[generics]{fit_xy}}, \code{\link[generics]{glance}}, \code{\link[generics]{tidy}}, \code{\link[generics]{varying_args}}} \item{magrittr}{\code{\link[magrittr:pipe]{\%>\%}}} }} From a46ca92223e48b25945f4c6f4726705c4b404166 Mon Sep 17 00:00:00 2001 From: Max Kuhn Date: Tue, 28 Jul 2020 19:51:40 -0400 Subject: [PATCH 2/2] updated GHA --- .github/workflows/R-CMD-check.yaml | 13 ++++++------- .github/workflows/pkgdown.yaml | 13 +++++-------- .github/workflows/pr-commands.yaml | 4 ++++ README.Rmd | 2 ++ README.md | 9 ++++++--- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 1f6a4391b..17efced74 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -15,10 +15,10 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'devel'} - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: windows-latest, r: '3.6'} + - {os: ubuntu-16.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} @@ -54,12 +54,11 @@ jobs: - name: Install system dependencies if: runner.os == 'Linux' - env: - RHUB_PLATFORM: linux-x86_64-ubuntu-gcc run: | - Rscript -e "remotes::install_github('r-hub/sysreqs')" - sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") - sudo -s eval "$sysreqs" + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'cat(remotes::system_requirements("ubuntu", "16.04"), sep = "\n")') - name: Install dependencies run: | @@ -102,7 +101,7 @@ jobs: - name: Upload check results if: failure() - uses: actions/upload-artifact@master + uses: actions/upload-artifact@main with: name: ${{ runner.os }}-r${{ matrix.config.r }}-results path: check diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index ad9e0fc53..8bc92105d 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -32,18 +32,15 @@ jobs: - name: Install dependencies run: | - install.packages("remotes") remotes::install_deps(dependencies = TRUE) - remotes::install_dev("pkgdown") - remotes::install_github("tidyverse/tidytemplate") - remotes::install_cran("tidymodels") - remotes::install_cran("C50") - remotes::install_cran("modeldata") + install.packages("pkgdown") shell: Rscript {0} - name: Install package run: R CMD INSTALL . - name: Deploy package - run: pkgdown::deploy_to_branch(new_process = FALSE) - shell: Rscript {0} + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml index 0d3cb7162..1ae5d594f 100644 --- a/.github/workflows/pr-commands.yaml +++ b/.github/workflows/pr-commands.yaml @@ -21,6 +21,8 @@ jobs: run: Rscript -e 'roxygen2::roxygenise()' - name: commit run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" git add man/\* NAMESPACE git commit -m 'Document' - uses: r-lib/actions/pr-push@master @@ -44,6 +46,8 @@ jobs: run: Rscript -e 'styler::style_pkg()' - name: commit run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" git add \*.R git commit -m 'Style' - uses: r-lib/actions/pr-push@master diff --git a/README.Rmd b/README.Rmd index 1b31a0d4d..9d06e3be7 100644 --- a/README.Rmd +++ b/README.Rmd @@ -21,6 +21,7 @@ knitr::opts_chunk$set( [![CRAN status](https://www.r-pkg.org/badges/version/parsnip)](https://CRAN.R-project.org/package=parsnip) [![Downloads](http://cranlogs.r-pkg.org/badges/parsnip)](https://cran.rstudio.com/package=parsnip) [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) +[![R build status](https://github.com/tidymodels/parsnip/workflows/R-CMD-check/badge.svg)](https://github.com/tidymodels/parsnip/actions) ## Introduction @@ -112,6 +113,7 @@ rand_forest(mtry = 10, trees = 2000) %>% Either one of these model specifications can be fit in the same way: ```{r} +set.seed(192) rand_forest(mtry = 10, trees = 2000) %>% set_engine("ranger", importance = "impurity") %>% set_mode("regression") %>% diff --git a/README.md b/README.md index c02bd7a53..60175829a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ status](https://codecov.io/gh/tidymodels/parsnip/branch/master/graph/badge.svg)] status](https://www.r-pkg.org/badges/version/parsnip)](https://CRAN.R-project.org/package=parsnip) [![Downloads](http://cranlogs.r-pkg.org/badges/parsnip)](https://cran.rstudio.com/package=parsnip) [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) +[![R build +status](https://github.com/tidymodels/parsnip/workflows/R-CMD-check/badge.svg)](https://github.com/tidymodels/parsnip/actions) ## Introduction @@ -134,13 +136,14 @@ rand_forest(mtry = 10, trees = 2000) %>% Either one of these model specifications can be fit in the same way: ``` r +set.seed(192) rand_forest(mtry = 10, trees = 2000) %>% set_engine("ranger", importance = "impurity") %>% set_mode("regression") %>% fit(mpg ~ ., data = mtcars) #> parsnip model object #> -#> Fit time: 71ms +#> Fit time: 69ms #> Ranger result #> #> Call: @@ -154,8 +157,8 @@ rand_forest(mtry = 10, trees = 2000) %>% #> Target node size: 5 #> Variable importance mode: impurity #> Splitrule: variance -#> OOB prediction error (MSE): 5.699772 -#> R squared (OOB): 0.8430857 +#> OOB prediction error (MSE): 5.976917 +#> R squared (OOB): 0.8354559 ``` A list of all `parsnip` models across different CRAN packages can be