Skip to content
Merged
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: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
^CRAN-SUBMISSION$
^\.python-version$
^revdep$
^[.]?air[.]toml$
^\.vscode$
5 changes: 3 additions & 2 deletions .github/workflows/R-CMD-check-hard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
# dependency.
on:
push:
branches: [main]
branches: main
pull_request:
branches: [main]

name: R-CMD-check-hard

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ on:
push:
branches: main
pull_request:
branches: main

name: R-CMD-check

permissions: read-all

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
Expand All @@ -26,10 +27,10 @@ jobs:

- {os: windows-latest, r: 'release'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -70,3 +71,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
46 changes: 46 additions & 0 deletions .github/workflows/format-suggest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples

on:
# Using `pull_request_target` over `pull_request` for elevated `GITHUB_TOKEN`
# privileges, otherwise we can't set `pull-requests: write` when the pull
# request comes from a fork, which is our main use case (external contributors).
#
# `pull_request_target` runs in the context of the target branch (`main`, usually),
# rather than in the context of the pull request like `pull_request` does. Due
# to this, we must explicitly checkout `ref: ${{ github.event.pull_request.head.sha }}`.
# This is typically frowned upon by GitHub, as it exposes you to potentially running
# untrusted code in a context where you have elevated privileges, but they explicitly
# call out the use case of reformatting and committing back / commenting on the PR
# as a situation that should be safe (because we aren't actually running the untrusted
# code, we are just treating it as passive data).
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
pull_request_target:

name: format-suggest.yaml

jobs:
format-suggest:
name: format-suggest
runs-on: ubuntu-latest

permissions:
# Required to push suggestion comments to the PR
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install
uses: posit-dev/setup-air@v1

- name: Format
run: air format .

- name: Suggest
uses: reviewdog/action-suggester@v1
with:
level: error
fail_level: error
tool_name: air
7 changes: 4 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: main
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -57,7 +58,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: main
pull_request:
branches: main

name: test-coverage

Expand Down Expand Up @@ -51,9 +50,19 @@ jobs:
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v5
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
files: ./cobertura.xml
plugins: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
Expand All @@ -67,4 +76,3 @@ jobs:
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package

5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"Posit.air-vscode"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
},
"[quarto]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "quarto.quarto"
}
}
13 changes: 8 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Authors@R: c(
person("Simon", "Couch", , "simonpatrickcouch@gmail.com", role = "aut"),
person("Qiushi", "Yan", , "qiushi.yann@gmail.com", role = "aut"),
person("Max", "Kuhn", , "max@posit.co", role = "aut"),
person("Posit Software, PBC", role = c("cph", "fnd"))
person("Posit Software, PBC", role = c("cph", "fnd"),
comment = c(ROR = "03wc8by49"))
)
Description: Typically, models in 'R' exist in memory and can be saved via
regular 'R' serialization. However, some models store information in
Expand All @@ -19,9 +20,10 @@ License: MIT + file LICENSE
URL: https://github.com/rstudio/bundle, https://rstudio.github.io/bundle/
BugReports: https://github.com/rstudio/bundle/issues
Depends:
R (>= 3.6)
R (>= 4.1)
Imports:
glue,
lifecycle,
purrr,
rlang,
utils,
Expand Down Expand Up @@ -56,10 +58,11 @@ Suggests:
xgboost (>= 1.6.0.1)
VignetteBuilder:
knitr
Remotes:
tidymodels/butcher
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Config/usethis/last-upkeep: 2025-12-08
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Remotes:
tidymodels/butcher
RoxygenNote: 7.3.3
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2023
YEAR: 2025
COPYRIGHT HOLDER: bundle authors
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2023 bundle authors
Copyright (c) 2025 bundle authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export(bundle_constr)
export(situate_constr)
export(swap_element)
export(unbundle)
importFrom(purrr,"%>%")
importFrom(lifecycle,deprecated)
7 changes: 7 additions & 0 deletions R/bundle-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @importFrom lifecycle deprecated
## usethis namespace: end
NULL
6 changes: 4 additions & 2 deletions R/bundle_bart.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ bundle.bart <- function(x, ...) {
# `parsnip::bart()` and `dbarts::bart()` unfortunately both inherit from `bart`
if (inherits(x, "model_spec")) {
rlang::abort(c(
paste0("`x` should be the output of `dbarts::bart()`, not a model ",
"specification from `parsnip::bart()`."),
paste0(
"`x` should be the output of `dbarts::bart()`, not a model ",
"specification from `parsnip::bart()`."
),
"To bundle `parsnip::bart()` output, train it with `parsnip::fit()` first."
))
}
Expand Down
6 changes: 3 additions & 3 deletions R/bundle_embed.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#'
#' set.seed(1)
#'
#' rec <- recipe(Species ~ ., data = iris) %>%
#' step_normalize(all_predictors()) %>%
#' step_umap(all_predictors(), outcome = vars(Species), num_comp = 2) %>%
#' rec <- recipe(Species ~ ., data = iris) |>
#' step_normalize(all_predictors()) |>
#' step_umap(all_predictors(), outcome = vars(Species), num_comp = 2) |>
#' prep()
#'
#' rec_bundle <- bundle(rec)
Expand Down
19 changes: 11 additions & 8 deletions R/bundle_keras.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@
#'
#' mod <- keras_model_sequential()
#'
#' mod %>%
#' layer_dense(units = 128, activation = 'relu', input_shape = c(784)) %>%
#' layer_dropout(rate = 0.4) %>%
#' layer_dense(units = 64, activation = 'relu') %>%
#' layer_dropout(rate = 0.3) %>%
#' mod |>
#' layer_dense(units = 128, activation = 'relu', input_shape = c(784)) |>
#' layer_dropout(rate = 0.4) |>
#' layer_dense(units = 64, activation = 'relu') |>
#' layer_dropout(rate = 0.3) |>
#' layer_dense(units = 10, activation = 'softmax')
#'
#' mod %>% compile(
#' mod |> compile(
#' loss = 'categorical_crossentropy',
#' optimizer = optimizer_rmsprop(),
#' metrics = c('accuracy')
#' )
#'
#' mod %>% fit(
#' mod |> fit(
#' x_train, y_train,
#' epochs = 5, batch_size = 128,
#' validation_split = 0.2,
Expand Down Expand Up @@ -90,7 +90,10 @@ bundle.keras.engine.training.Model <- function(x, ...) {
bundle_constr(
object = serialized,
situate = situate_constr(function(object) {
new_file <- withr::local_tempfile(pattern = "unbundle", fileext = ".tar.gz")
new_file <- withr::local_tempfile(
pattern = "unbundle",
fileext = ".tar.gz"
)
unbundle_dir <- withr::local_tempdir("unbundle")
writeBin(object, new_file, endian = "little")
utils::untar(new_file, exdir = unbundle_dir)
Expand Down
6 changes: 3 additions & 3 deletions R/bundle_parsnip.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#' set.seed(1)
#'
#' mod <-
#' boost_tree(trees = 5, mtry = 3) %>%
#' set_mode("regression") %>%
#' set_engine("xgboost") %>%
#' boost_tree(trees = 5, mtry = 3) |>
#' set_mode("regression") |>
#' set_engine("xgboost") |>
#' fit(mpg ~ ., data = mtcars)
#'
#' mod_bundle <- bundle(mod)
Expand Down
8 changes: 4 additions & 4 deletions R/bundle_stacks.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#' set.seed(1)
#'
#' mod <-
#' stacks() %>%
#' add_candidates(reg_res_lr) %>%
#' add_candidates(reg_res_svm) %>%
#' blend_predictions(times = 10) %>%
#' stacks() |>
#' add_candidates(reg_res_lr) |>
#' add_candidates(reg_res_svm) |>
#' blend_predictions(times = 10) |>
#' fit_members()
#'
#' mod_bundle <- bundle(mod)
Expand Down
19 changes: 11 additions & 8 deletions R/bundle_torch.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@
#' )
#' },
#' forward = function(x) {
#' x %>%
#' self$encoder() %>%
#' x |>
#' self$encoder() |>
#' self$decoder()
#' },
#' predict = function(x) {
#' self$encoder(x) %>%
#' self$encoder(x) |>
#' torch_flatten(start_dim = 2)
#' }
#' )
#'
#' mod <- net %>%
#' mod <- net |>
#' setup(
#' loss = nn_mse_loss(),
#' optimizer = optim_adam
#' ) %>%
#' ) |>
#' fit(train_dl, epochs = 1, valid_data = test_dl)
#'
#' mod_bundle <- bundle(mod)
Expand Down Expand Up @@ -116,9 +116,12 @@ bundle.luz_module_fitted <- function(x, ...) {
object = res,
situate = situate_constr(function(object) {
con <- rawConnection(object)
on.exit({
close(con)
}, add = TRUE)
on.exit(
{
close(con)
},
add = TRUE
)
res <- luz::luz_load(con)
}),
desc_class = class(x)[1]
Expand Down
Loading