Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add butcher methods for mixOmics output #249

Merged
merged 6 commits into from Jan 25, 2023
Merged

add butcher methods for mixOmics output #249

merged 6 commits into from Jan 25, 2023

Conversation

simonpcouch
Copy link
Contributor

@simonpcouch simonpcouch commented Jan 23, 2023

These methods do a good job of being selective about what they bring along from the enclosing env, and do make use of most all of the heavier bits of inputted data that they retain at predict time—not a lot of memory released, in the end.

mixo_plsda objects are a subclass of mixo_pls, so don’t need their own methods!

The mixOmics package is hosted on Bioconductor rather than CRAN, so this PR doesn’t introduce mixOmics as a dependency. This also means that mixOmics methods won’t be tested on CRAN or CI.

library(butcher)
library(mixOmics)
#> Loading required package: MASS
#> Loading required package: lattice
#> Loading required package: ggplot2
#> 
#> Loaded mixOmics 6.20.0
#> Thank you for using mixOmics!
#> Tutorials: http://mixomics.org
#> Bookdown vignette: https://mixomicsteam.github.io/Bookdown
#> Questions, issues: Follow the prompts at http://mixomics.org/contact-us
#> Cite us:  citation('mixOmics')

fit_mod <- function() {
  boop <- runif(1e6)
  pls(matrix(rnorm(2e4), ncol = 2), rnorm(1e4), mode = "classic")
}

mod_fit <- fit_mod()
mod_res <- butcher(mod_fit)

weigh(mod_fit)
#> # A tibble: 24 × 2
#>    object             size
#>    <chr>             <dbl>
#>  1 X              0.801   
#>  2 variates.X     0.801   
#>  3 variates.Y     0.801   
#>  4 Y              0.721   
#>  5 names.sample   0.640   
#>  6 input.X        0.161   
#>  7 call           0.00129 
#>  8 loadings.X     0.000776
#>  9 loadings.Y     0.000696
#> 10 loadings.star1 0.0006  
#> # … with 14 more rows
weigh(mod_res)
#> # A tibble: 24 × 2
#>    object              size
#>    <chr>              <dbl>
#>  1 X               0.801   
#>  2 variates.X      0.801   
#>  3 variates.Y      0.801   
#>  4 Y               0.721   
#>  5 loadings.X      0.000776
#>  6 loadings.Y      0.000696
#>  7 loadings.star1  0.0006  
#>  8 mat.c           0.0006  
#>  9 loadings.star2  0.00052 
#> 10 prop_expl_var.X 0.000352
#> # … with 14 more rows

new_data <- matrix(1:2, ncol = 2)
colnames(new_data) <- c("X1", "X2")

testthat::expect_equal(
  purrr::discard_at(predict(mod_fit, new_data), "call"),
  purrr::discard_at(predict(mod_res, new_data), "call")
)

Created on 2023-01-23 with reprex v2.0.2

Related to #234.

@juliasilge
Copy link
Member

Do you think it would be worth it to install the package into the check action, so the tests get run on CI? Or not very worthwhile?

@simonpcouch
Copy link
Contributor Author

simonpcouch commented Jan 25, 2023

I think that's a good idea. :) Added in 0d607c5.

EDIT: Seeing those failures, trying to debug🤔

Copy link
Member

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great -- thank you again! 👨‍🎤

@juliasilge juliasilge merged commit 82065a1 into main Jan 25, 2023
@juliasilge juliasilge deleted the mixOmics-234 branch January 25, 2023 18:11
@github-actions
Copy link

github-actions bot commented Feb 9, 2023

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants