Skip to content

Commit 18004ab

Browse files
authored
Merge pull request #413 from tidymodels/control-classes
Control classes
2 parents 465f1d7 + f029662 commit 18004ab

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

.github/workflows/check-pak.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# NOTE: This workflow is overkill for most R packages
2+
# check-standard.yaml is likely a better choice
3+
# usethis::use_github_action("check-standard") will install it.
4+
#
5+
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
6+
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
7+
on:
8+
push:
9+
branches:
10+
- main
11+
- master
12+
pull_request:
13+
branches:
14+
- main
15+
- master
16+
17+
name: R-CMD-check-pak
18+
19+
jobs:
20+
R-CMD-check:
21+
runs-on: ${{ matrix.config.os }}
22+
23+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
config:
29+
- {os: macOS-latest, r: 'release'}
30+
- {os: windows-latest, r: 'release'}
31+
- {os: windows-latest, r: '3.6'}
32+
- {os: ubuntu-16.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest", http-user-agent: "R/4.0.0 (ubuntu-16.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
33+
- {os: ubuntu-16.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
34+
- {os: ubuntu-16.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
35+
- {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
36+
37+
env:
38+
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
39+
RSPM: ${{ matrix.config.rspm }}
40+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
41+
42+
steps:
43+
- uses: actions/checkout@v2
44+
45+
- uses: r-lib/actions/setup-r@v1
46+
id: install-r
47+
with:
48+
r-version: ${{ matrix.config.r }}
49+
http-user-agent: ${{ matrix.config.http-user-agent }}
50+
51+
- uses: r-lib/actions/setup-pandoc@v1
52+
53+
- name: Install pak and query dependencies
54+
run: |
55+
install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
56+
saveRDS(pak::pkg_deps_tree("local::.", dependencies = TRUE), ".github/r-depends.rds")
57+
shell: Rscript {0}
58+
59+
- name: Cache R packages
60+
uses: actions/cache@v2
61+
with:
62+
path: ${{ env.R_LIBS_USER }}
63+
key: ${{ runner.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-${{ hashFiles('.github/r-depends.rds') }}
64+
restore-keys: ${{ runner.os }}-${{ steps.install-r.outputs.installed-r-version }}-1-
65+
66+
- name: Install system dependencies
67+
if: runner.os == 'Linux'
68+
run: Rscript -e 'pak::local_system_requirements(execute = TRUE)'
69+
70+
- name: Install dependencies
71+
run: |
72+
pak::local_install_dev_deps(upgrade = TRUE)
73+
pak::pkg_install("rcmdcheck")
74+
shell: Rscript {0}
75+
76+
- name: Install Miniconda
77+
run: |
78+
Rscript -e "pak::pkg_install('rstudio/reticulate')"
79+
Rscript -e "reticulate::install_miniconda()"
80+
81+
- name: Find Miniconda on macOS
82+
if: runner.os == 'macOS'
83+
run: echo "options(reticulate.conda_binary = reticulate:::miniconda_conda())" >> .Rprofile
84+
85+
- name: Install TensorFlow
86+
run: |
87+
reticulate::conda_create('r-reticulate', packages = c('python==3.6.9'))
88+
tensorflow::install_tensorflow(version='1.14.0')
89+
shell: Rscript {0}
90+
91+
- name: Session info
92+
run: |
93+
options(width = 100)
94+
pkgs <- installed.packages()[, "Package"]
95+
sessioninfo::session_info(pkgs, include_base = TRUE)
96+
shell: Rscript {0}
97+
98+
- name: Check
99+
env:
100+
_R_CHECK_CRAN_INCOMING_: false
101+
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
102+
shell: Rscript {0}
103+
104+
- name: Show testthat output
105+
if: always()
106+
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
107+
shell: bash
108+
109+
- name: Upload check results
110+
if: failure()
111+
uses: actions/upload-artifact@main
112+
with:
113+
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
114+
path: check

R/fit.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ fit.model_spec <-
100100
if (object$mode == "unknown") {
101101
rlang::abort("Please set the mode in the model specification.")
102102
}
103+
if (!identical(class(control), class(control_parsnip()))) {
104+
rlang::abort("The 'control' argument should have class 'control_parsnip'.")
105+
}
103106
dots <- quos(...)
104107
if (is.null(object$engine)) {
105108
eng_vals <- possible_engines(object)
@@ -189,6 +192,9 @@ fit_xy.model_spec <-
189192
control = control_parsnip(),
190193
...
191194
) {
195+
if (!identical(class(control), class(control_parsnip()))) {
196+
rlang::abort("The 'control' argument should have class 'control_parsnip'.")
197+
}
192198
object <- check_mode(object, levels(y))
193199
dots <- quos(...)
194200
if (is.null(object$engine)) {

tests/testthat/test_misc.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,22 @@ test_that('S3 method dispatch/registration', {
8585
)
8686
expect_true(tibble::is_tibble(res))
8787

88+
})
8889

90+
# ------------------------------------------------------------------------------
8991

92+
test_that('control class', {
93+
x <- linear_reg() %>% set_engine("lm")
94+
ctrl <- control_parsnip()
95+
class(ctrl) <- c("potato", "chair")
96+
expect_error(
97+
fit(x, mpg ~ ., data = mtcars, control = ctrl),
98+
"The 'control' argument should have class 'control_parsnip'"
99+
)
100+
expect_error(
101+
fit_xy(x, x = mtcars[, -1], y = mtcars$mpg, control = ctrl),
102+
"The 'control' argument should have class 'control_parsnip'"
103+
)
90104
})
91105

92106

0 commit comments

Comments
 (0)