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

Delint and debug #273

Merged
merged 11 commits into from
Jun 27, 2024
Merged

Delint and debug #273

merged 11 commits into from
Jun 27, 2024

Conversation

zachmayer
Copy link
Owner

@zachmayer zachmayer commented Jun 26, 2024

@antongomez PR to delint the codebase. I'll then rebase my initial multiclass branch off this

Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Warning

Rate limit exceeded

@zachmayer has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 48 minutes and 17 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between fe24b61 and b35567d.

Walkthrough

The recent changes primarily focus on improving code readability, maintainability, and style consistency across the project. Significant updates include reformatting code to standardize spacing and alignment, especially around assignment operators, enhancing comments for clarity, and updating function parameter formats. Moreover, new configuration files for linters and build tools have been introduced, and the Makefile has been updated to streamline the build process by adding new targets and removing redundancy.

Changes

Files Change Summary
.Rbuildignore Added .coderabbit.yaml to the list of ignored files.
.coderabbit.yaml Introduced configuration settings for the yaml-language-server.
.lintr Adjusted linters configuration, modifying settings for line length, sequence, and cyclomatic complexity.
Makefile Updated default target order; added new targets update-test-fixtures and lint; removed test-coverage.
R/S3GenericExtentions.R Format adjustments in caretList and train functions for improved readability and consistency.
R/caretEnsemble-package.R Added comments and reformatted code for better clarity.
R/caretEnsemble.R Spacing adjustment around equals signs in function calls and parameters; enhanced readability.
R/caretList.R Standardized parameter names and improved code readability; fixed typos.
R/caretStack.R Improved readability through spacing and alignment adjustments in function calls.
R/helper_functions.R Enhanced code consistency and readability without changing functionality.
inst/data-raw/build_test_data.R Reformatted parameter assignments for better readability.
man/autoplot.Rd Reformatted code snippets for model creation within the caretEnsemble object.
man/c.caretList.Rd Improved formatting and alignment in code examples.
man/c.train.Rd Added spaces around equal signs and changed single quotes to double quotes.
tests/testthat.R Removed import of the caretEnsemble library.
tests/testthat/test-S3-generic-extensions.R Reformatted code by adding spaces around equal signs in function calls and assignments.
tests/testthat/test-caretList.R Reformatted code for better readability and consistency.

Sequence Diagram(s)

Since the changes primarily involve code reformatting, linting configuration, and Makefile updates, no new features or control flow modifications require visualization through sequence diagrams.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c69887 and c80fdca.

Files selected for processing (34)
  • .Rbuildignore (1 hunks)
  • .coderabbit.yaml (1 hunks)
  • .lintr (1 hunks)
  • Makefile (2 hunks)
  • R/S3GenericExtenstions.R (2 hunks)
  • R/caretEnsemble-package.R (1 hunks)
  • R/caretEnsemble.R (16 hunks)
  • R/caretList.R (13 hunks)
  • R/caretStack.R (8 hunks)
  • R/helper_functions.R (14 hunks)
  • inst/data-raw/build_test_data.R (2 hunks)
  • man/autoplot.Rd (1 hunks)
  • man/c.caretList.Rd (1 hunks)
  • man/c.train.Rd (1 hunks)
  • man/caretEnsemble.Rd (1 hunks)
  • man/caretList.Rd (1 hunks)
  • man/caretModelSpec.Rd (1 hunks)
  • man/caretStack.Rd (1 hunks)
  • man/dotplot.caretStack.Rd (1 hunks)
  • man/plot.caretEnsemble.Rd (1 hunks)
  • man/plot.caretStack.Rd (1 hunks)
  • man/predict.caretStack.Rd (1 hunks)
  • man/print.caretStack.Rd (1 hunks)
  • man/summary.caretEnsemble.Rd (1 hunks)
  • man/summary.caretStack.Rd (1 hunks)
  • tests/testthat/test-S3-generic-extensions.R (3 hunks)
  • tests/testthat/test-caretList.R (15 hunks)
  • tests/testthat/test-caretStack.R (4 hunks)
  • tests/testthat/test-classSelection.R (6 hunks)
  • tests/testthat/test-ensemble.R (10 hunks)
  • tests/testthat/test-ensembleMethods.R (11 hunks)
  • tests/testthat/test-helper_functions.R (7 hunks)
  • tests/testthat/test-parallel.R (2 hunks)
  • vignettes/caretEnsemble-intro.Rmd (7 hunks)
Files not reviewed due to errors (1)
  • tests/testthat/test-classSelection.R (no review received)
Files skipped from review due to trivial changes (28)
  • .Rbuildignore
  • .coderabbit.yaml
  • R/caretEnsemble-package.R
  • R/caretEnsemble.R
  • R/caretList.R
  • R/caretStack.R
  • R/helper_functions.R
  • inst/data-raw/build_test_data.R
  • man/autoplot.Rd
  • man/c.caretList.Rd
  • man/c.train.Rd
  • man/caretEnsemble.Rd
  • man/caretList.Rd
  • man/caretModelSpec.Rd
  • man/caretStack.Rd
  • man/plot.caretEnsemble.Rd
  • man/plot.caretStack.Rd
  • man/predict.caretStack.Rd
  • man/print.caretStack.Rd
  • man/summary.caretEnsemble.Rd
  • man/summary.caretStack.Rd
  • tests/testthat/test-S3-generic-extensions.R
  • tests/testthat/test-caretStack.R
  • tests/testthat/test-ensemble.R
  • tests/testthat/test-ensembleMethods.R
  • tests/testthat/test-helper_functions.R
  • tests/testthat/test-parallel.R
  • vignettes/caretEnsemble-intro.Rmd
Additional comments not posted (11)
.lintr (2)

4-4: Cyclomatic complexity linter added.

This addition helps maintain code quality by enforcing a complexity limit of 16, which is a common threshold for maintaining manageable function complexity.


2-2: Consider updating the line length as planned.

The TODO comment suggests a planned reduction in line length from 305 to 120, which aligns with common coding standards for better readability.

man/dotplot.caretStack.Rd (1)

24-29: Updated example code in documentation.

The example code has been updated to reflect the correct usage of the caretList and caretStack functions with proper formatting and method assignments. Ensure that these examples are tested to verify their correctness.

Also applies to: 33-33

Makefile (1)

3-3: Updated Makefile with new targets and order.

The Makefile has been restructured to include new targets such as update-test-fixtures and fix-style, and to change the default build sequence. This should enhance the development process by ensuring that style fixes and tests are prioritized.

Also applies to: 6-6, 18-21, 30-34, 36-37

R/S3GenericExtenstions.R (1)

14-21: Enhanced documentation and error handling in S3 methods.

The documentation examples have been updated for clarity and accuracy. Additionally, the functions now include better error handling to ensure that only caretList or train objects are processed, which enhances robustness.

Also applies to: 24-31, 33-33, 38-39, 86-87

tests/testthat/test-caretList.R (6)

99-104: Testing different configurations of trainControl and methods

The modifications in the trainControl function parameters and method list are aimed at testing different configurations. Confirm that these changes are consistent with the intended testing scenarios and that all configurations are adequately covered.


77-82: Enhanced testing configurations for edge cases

The introduction of specific testing configurations for caretModelSpec improves coverage of potential edge cases, ensuring robustness. Verify that these configurations are tested across different scenarios and align with the overall testing strategy.

Verification successful

Enhanced testing configurations for edge cases

The introduction of specific testing configurations for caretModelSpec improves coverage of potential edge cases, ensuring robustness. The function caretModelSpec is tested across various scenarios in multiple test files, demonstrating a comprehensive testing strategy.

  • tests/testthat/test-ensemble.R
  • tests/testthat/test-S3-generic-extensions.R
  • tests/testthat/test-caretList.R
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the testing configurations across different scenarios.

# Test: Search for similar configurations in other test files.
rg --type R $'caretModelSpec'

Length of output: 54



Script:

#!/bin/bash
# Description: Verify the testing configurations across different scenarios.

# Test: Search for similar configurations in other test files.
rg --glob '*.R' 'caretModelSpec'

Length of output: 3442


190-208: Comprehensive testing of different CV methods

The adjustments in the trainControl function parameters for different CV methods enhance the test's comprehensiveness. Ensure that all CV methods are correctly handled and that the test scenarios reflect realistic use cases.

Verification successful

Comprehensive testing of different CV methods

The adjustments in the trainControl function parameters for different CV methods enhance the test's comprehensiveness. The different CV methods are correctly handled, and the test scenarios reflect realistic use cases.

  • Verified instances of trainControl usage in various test scenarios across the project.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the handling of different CV methods in the test environment.

# Test: Search for different CV methods across the project.
rg --type R $'trainControl'

Length of output: 52



Script:

#!/bin/bash
# Description: Verify the handling of different CV methods in the test environment.

# Find all R files and search for the usage of trainControl
fd -e R -x rg 'trainControl' {}

Length of output: 5223


27-30: Improved clarity in method specification

The explicit setting of method parameters in caretModelSpec calls enhances clarity and ensures the correct methods are being tested. Verify that these method specifications align with intended test coverage.

Verification successful

Improved clarity in method specification

The explicit setting of method parameters in caretModelSpec calls enhances clarity and ensures the correct methods are being tested. The method specifications align well with the intended test coverage.

  • tests/testthat/test-caretList.R: Lines 27-30
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the alignment of method specifications with intended test coverage.

# Test: Search for the method specifications across the project.
rg --type R $'caretModelSpec'

Length of output: 54



Script:

#!/bin/bash
# Description: Verify the alignment of method specifications with intended test coverage.

# Locate all R files and search for `caretModelSpec` calls within those files.
fd -e R -x rg 'caretModelSpec' {}

Length of output: 2336


451-463: Testing custom tuneList with specific parameters

The setup of a custom tuneList with specific tuning parameters is crucial for testing the flexibility and robustness of the model training process. Verify that these parameters are correctly handled and that the test scenarios are comprehensive.

Verification successful

Testing custom tuneList with specific parameters

The setup of a custom tuneList with specific tuning parameters is crucial for testing the flexibility and robustness of the model training process. The verification confirms that these parameters are correctly handled and that the test scenarios are comprehensive.

  • tests/testthat/test-caretList.R: Multiple occurrences of tuneList usage.
  • tests/testthat/test-ensemble.R: tuneList used in different test scenarios.
  • Documentation files also reference tuneList, indicating detailed usage instructions.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the handling of custom tuneList parameters in the test environment.

# Test: Search for the usage of custom tuneList parameters across the project.
rg --type R $'tuneList'

Length of output: 48



Script:

#!/bin/bash
# Description: Verify the handling of custom tuneList parameters in the test environment.

# Test: Search for the usage of custom tuneList parameters across the project.
rg 'tuneList'

Length of output: 5265


15-16: Enhanced test setup for robustness

The changes in the parameters for twoClassSim seem intended to enhance the test's robustness by adjusting the correlation variables and values. Confirm that these values align with the expected testing scenarios.

Also applies to: 19-20

Verification successful

Enhanced test setup for robustness

The changes in the parameters for twoClassSim seem intended to enhance the test's robustness by adjusting the correlation variables and values. The updated parameters align with the expected testing scenarios.

  • tests/testthat/test-caretList.R: lines 15-16 and 19-20
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage and impact of the new parameters in the test environment.

# Test: Search for the function usage in other test files.
rg --type R $'twoClassSim'

Length of output: 51



Script:

#!/bin/bash
# Description: Verify the usage and impact of the new parameters in the test environment.

# Test: Search for the function usage in other test files.
rg 'twoClassSim' --glob '*.R'

Length of output: 136



Script:

#!/bin/bash
# Description: Extract lines where `twoClassSim` is called in the `tests/testthat/test-caretList.R` file to verify parameter changes.

# Extract relevant lines from the test file.
rg 'twoClassSim' --glob 'tests/testthat/test-caretList.R' -A 3 -B 3

Length of output: 688

.lintr Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c80fdca and fe24b61.

Files selected for processing (14)
  • .lintr (1 hunks)
  • R/caretList.R (13 hunks)
  • R/helper_functions.R (14 hunks)
  • inst/data-raw/build_test_data.R (2 hunks)
  • tests/testthat.R (1 hunks)
  • tests/testthat/test-S3-generic-extensions.R (4 hunks)
  • tests/testthat/test-a-skip.R (1 hunks)
  • tests/testthat/test-caretList.R (15 hunks)
  • tests/testthat/test-caretStack.R (3 hunks)
  • tests/testthat/test-ensemble.R (10 hunks)
  • tests/testthat/test-ensembleMethods.R (11 hunks)
  • tests/testthat/test-helper_functions.R (7 hunks)
  • tests/testthat/test-parallel.R (2 hunks)
  • vignettes/caretEnsemble-intro.Rmd (5 hunks)
Files skipped from review due to trivial changes (1)
  • tests/testthat.R
Files skipped from review as they are similar to previous changes (12)
  • .lintr
  • R/caretList.R
  • R/helper_functions.R
  • inst/data-raw/build_test_data.R
  • tests/testthat/test-S3-generic-extensions.R
  • tests/testthat/test-caretList.R
  • tests/testthat/test-caretStack.R
  • tests/testthat/test-ensemble.R
  • tests/testthat/test-ensembleMethods.R
  • tests/testthat/test-helper_functions.R
  • tests/testthat/test-parallel.R
  • vignettes/caretEnsemble-intro.Rmd
Additional comments not posted (2)
tests/testthat/test-a-skip.R (2)

4-4: Ensure intentional failure is correct for testing.

The test intentionally fails by asserting expect_equal(1, 0). If this is meant to test the skip functionality, it's correctly placed after the skip call to ensure it does not execute.


8-8: Proper use of conditional skipping for CRAN environments.

The use of skip_on_cran() is appropriate for tests that should not run in the CRAN environment but are valid in other contexts. The test itself is a simple check that effectively serves as a placeholder to ensure test mechanics are correct when not skipped.

stop("Not yet implemented for multiclass problems")
# Warn that we have not yet implemented multiclass models
# add a check that if this is null you did not set savePredictions in the trainControl
# TODO: add support for non-prob models (e.g. rFerns)
Copy link
Owner Author

@zachmayer zachmayer Jun 27, 2024

Choose a reason for hiding this comment

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

Small bug fix here: this is more than just linting. Resolve an error if the first model in the list is different from the others.

Un-commented the test here, which had a comment about the bug: https://github.com/zachmayer/caretEnsemble/pull/273/files#diff-ba47473171653c28531fd5772a47eea8a0311c9fa86cb171a069253888444b95L52

#NOT YET SUPPORTED
# y <- factor(ifelse(iris[,5]=="versicolor", "yes", "no"))
# mod <- train(iris[,1:2], y, method="glm", trControl=trainControl(method="cv", number=3, savePredictions=TRUE))
# r <- residuals(mod)
Copy link
Owner Author

Choose a reason for hiding this comment

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

caret.residuals doesn't support classification models (lets update it sometime so it does, and while we're add it save class probs by default)

@@ -30,22 +29,21 @@ test_that("We can get variable importance in ensembles", {
expect_is(varImp(ens.reg, scale = TRUE, weight = TRUE), "data.frame")
})

test_that("We get warnings when scale is set to FALSE and weight is TRUE", {
skip_on_cran()
test_that("varImp works for caretEnsembles", {
Copy link
Owner Author

Choose a reason for hiding this comment

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

made this test easier to follow with a loop (instead of the unrolled loop), and checks for the rows/cols at each loop iteration.

#expect_true(identical(round(mr2[mr2$method == "rpart", "resid"], 5), round(mr2.tmp2, 5)))

#I think the factors are backward somewhere in here
#Also, caret doesn't yet support residuals for classification
Copy link
Owner Author

Choose a reason for hiding this comment

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

deleted as caret doesn't support residuals for classificaiton.

newDat <- ens.class$models[[3]]$trainingData
newDat[2, 2] <- NA
newDat[3, 3] <- NA
newDat[4, 4] <- NA
newDat <- newDat[1:10, ]
# expect_error(predict(ens.class, newdata = newDat, return_weights=TRUE, se=FALSE)) # BUG
Copy link
Owner Author

Choose a reason for hiding this comment

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

fixed this bug by re-adding the random forest model to the ens.class (note that the rest are ens.reg). The "bug" was because the random forest model is the only one that can't handle these NAs and thus returns an error.

So in the old test, no RF meant no error. Now that every test case has an RF, they all fail.

)
models2 <- c(new_model, models)
models3 <- c(models, new_model)
check_caretList_model_types(models)
expect_error(check_caretList_model_types(models2))
#expect_error(check_caretList_model_types(models3)) #THIS IS A BUG THAT NEEDS FIXING!!!!!!!!!!
Copy link
Owner Author

Choose a reason for hiding this comment

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

The fix above that checks all models, not just the first in the list, fixes this bug

Copy link
Owner Author

Choose a reason for hiding this comment

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

@zachmayer zachmayer merged commit 02bcc1f into main Jun 27, 2024
8 checks passed
@zachmayer zachmayer deleted the delint branch June 27, 2024 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant