Skip to content
/ bundle Public
forked from rstudio/bundle

Serialize Objects With A Consistent Interface

License

Notifications You must be signed in to change notification settings

topepo/bundle

 
 

Repository files navigation

bundle

NOTE: This package is very early on in its development and is not yet minimally functional.

Lifecycle: experimental CRAN status Codecov test coverage R-CMD-check

R holds most objects in memory. However, some models store their data in locations that are not included when one uses save() or saveRDS(). bundle provides a common API to capture this information, situate it within a portable object, and restore it for use in new settings.

Installation

You can install the development version of bundle like so:

pak::pak("simonpcouch/bundle")

Example

A common use case for serialization in R is the storing of model objects for later use in prediction tasks. For instance, we can train a boosted tree model, serialize it, and then later load it into another R session to generate predictions on new data:

library(bundle)
library(parsnip)
library(callr)

# fit an boosted tree with xgboost via parsnip
mod <-
    boost_tree(trees = 5, mtry = 3) %>%
    set_mode("regression") %>%
    set_engine("xgboost") %>%
    fit(mpg ~ ., data = mtcars[1:25,])

# bundle the model
bundled_mod <-
  bundle(mod)

# load the model in a fresh R session and predict on new data
r(
  func = function(bundled_mod) {
    library(bundle)
    library(parsnip)
    
    unbundled_mod <- 
      unbundle(bundled_mod)

    predict(unbundled_mod, new_data = mtcars[26:32,])
  },
  args = list(
    bundled_mod = bundled_mod
  )
)
#> # A tibble: 7 × 1
#>   .pred
#>   <dbl>
#> 1  22.1
#> 2  20.3
#> 3  18.3
#> 4  16.1
#> 5  18.3
#> 6  11.6
#> 7  20.7

Code of Conduct

Please note that the bundle project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

About

Serialize Objects With A Consistent Interface

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • R 100.0%