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

Lint #297

Merged
merged 15 commits into from
Aug 1, 2024
Merged

Lint #297

merged 15 commits into from
Aug 1, 2024

Conversation

zachmayer
Copy link
Owner

Fully delint, only todo linter and object linter left

Copy link
Contributor

coderabbitai bot commented Aug 1, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes reflect significant updates across the caret package, focusing on enhancing error handling, optimizing performance, and refining testing practices. Key modifications include the removal of several linters, improvements in error messages by suppressing call stacks, and increased robustness in unit tests through stricter assertions. These adjustments aim to improve code clarity, maintainability, and the overall user experience while ensuring rigorous testing standards.

Changes

File(s) Change Summary
.lintr Removed the tags array and set several linters to NULL, indicating a streamlined linter configuration and potential deprecation of certain checks.
R/S3GenericExtenstions.R Updated error handling in c.caretList and c.train functions to suppress call stack in error messages, improving output clarity.
R/caretEnsemble.R, R/caretList.R Enhanced error handling and performance optimizations by using vapply, replaced paste with toString, and improved function call structures.
R/caretPredict.R, R/caretStack.R Modified error and warning handling to suppress call stacks, improving readability of messages and adding new helper functions for better modularity.
R/caretTrain.R Updated error handling with tryCatch and suppressed call stack in warnings for better user experience.
cobertura.xml Contains coverage metrics for the caretEnsemble package, indicating full line coverage and details of methods and classes included in the package.
man/check_caretStack.Rd, man/set_excluded_class_id.Rd Added documentation for new functions to improve usability and clarity in the package framework.
tests/testthat/*.R Replaced expect_equal with expect_identical in various tests for stricter validation and enhanced reliability of assertions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CaretPackage
    participant ErrorHandler
    participant Linter

    User->>CaretPackage: Execute code with linter checks
    CaretPackage->>Linter: Run linters
    Linter-->>CaretPackage: Return results
    CaretPackage->>ErrorHandler: Handle any errors
    ErrorHandler-->>CaretPackage: Return refined error message
    CaretPackage-->>User: Display results
Loading
sequenceDiagram
    participant User
    participant CaretPackage
    participant TestSuite

    User->>TestSuite: Run tests on CaretPackage
    TestSuite->>CaretPackage: Execute functions
    CaretPackage-->>TestSuite: Return outputs
    TestSuite->>TestSuite: Validate outputs with expect_identical
    TestSuite-->>User: Report test results
Loading

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 Configuration 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 18d55f6 and b9e1c0d.

Files selected for processing (18)
  • .lintr (1 hunks)
  • R/S3GenericExtenstions.R (2 hunks)
  • R/caretEnsemble.R (4 hunks)
  • R/caretList.R (11 hunks)
  • R/caretPredict.R (2 hunks)
  • R/caretStack.R (5 hunks)
  • R/caretTrain.R (1 hunks)
  • cobertura.xml (1 hunks)
  • man/check_caretStack.Rd (1 hunks)
  • man/set_excluded_class_id.Rd (1 hunks)
  • tests/testthat/test-S3-generic-extensions.R (2 hunks)
  • tests/testthat/test-caretEnsemble.R (6 hunks)
  • tests/testthat/test-caretList.R (19 hunks)
  • tests/testthat/test-caretStack.R (8 hunks)
  • tests/testthat/test-classSelection.R (1 hunks)
  • tests/testthat/test-ensembleMethods.R (4 hunks)
  • tests/testthat/test-helper_functions.R (13 hunks)
  • tests/testthat/test-multiclass.R (9 hunks)
Files skipped from review due to trivial changes (5)
  • R/S3GenericExtenstions.R
  • R/caretTrain.R
  • cobertura.xml
  • man/check_caretStack.Rd
  • man/set_excluded_class_id.Rd
Additional comments not posted (110)
.lintr (3)

2-2: LGTM!

Setting tags to NULL removes all categorization tags for linters, which might be intentional to simplify the configuration.


3-3: LGTM!

Setting todo_comment_linter to NULL disables the linter for TODO comments, which might be intentional to allow TODO comments in the code.


4-4: LGTM!

Setting object_name_linter to NULL disables the linter for object names, which might be intentional to allow flexibility in naming objects.

tests/testthat/test-classSelection.R (1)

39-39: LGTM!

Replacing sapply with vapply enhances type safety and performance by ensuring that the output is consistently of type character(1L).

R/caretPredict.R (7)

11-11: LGTM!

Adding call. = FALSE to the warning suppresses the call stack, making the warning message cleaner.


15-15: LGTM!

Adding call. = FALSE to the error suppresses the call stack, making the error message cleaner.


18-18: LGTM!

Adding call. = FALSE to the error suppresses the call stack, making the error message cleaner.


25-25: LGTM!

Adding call. = FALSE to the warning suppresses the call stack, making the warning message cleaner.


29-29: LGTM!

Using suppressWarnings ensures that any warnings during the conversion are suppressed, making the code cleaner.


34-34: LGTM!

Adding call. = FALSE to the error suppresses the call stack, making the error message cleaner.


37-37: LGTM!

Adding call. = FALSE to the error suppresses the call stack, making the error message cleaner.

tests/testthat/test-S3-generic-extensions.R (2)

180-180: Good use of vapply for type safety.

Replacing sapply with vapply ensures that the result is explicitly a character vector, improving type safety and clarity.


192-202: Stricter validation with expect_identical.

Replacing expect_equal with expect_identical ensures that the structure and type of the data tables returned by the predictions match the expected dimensions precisely.

tests/testthat/test-ensembleMethods.R (3)

42-42: Stricter validation with expect_identical.

Replacing expect_equal with expect_identical ensures that the variable names are not only equal in value but also of the same type and structure.


51-54: Stricter validation with expect_identical.

Replacing expect_equal with expect_identical ensures that the structure and type of the data tables returned by the predictions match the expected dimensions precisely.


129-133: Stricter validation with expect_identical and expect_named.

Replacing expect_equal with expect_identical and expect_named ensures that the structure and type of the data tables and the names of the columns match the expected values precisely.

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

14-14: Stricter validation with expect_identical.

Replacing expect_equal with expect_identical ensures that the number of rows in the predictions matches the expected value precisely.


24-24: Stricter validation with expect_identical.

Replacing expect_equal with expect_identical ensures that the number of rows in the predictions matches the expected value precisely.


43-43: Stricter validation with expect_identical.

Replacing expect_equal with expect_identical ensures that the dimensions of the predictions match the expected values precisely.


54-54: Stricter validation with expect_named.

Replacing expect_equal with expect_named ensures that the names of the columns in the predictions match the expected values precisely.


76-76: Stricter validation with expect_identical.

Replacing expect_equal with expect_identical ensures that the dimensions of the predictions match the expected values precisely.


Line range hint 213-251:
Stricter validation with expect_identical and expect_named.

Replacing expect_equal with expect_identical and expect_named ensures that the structure and type of the data tables and the names of the columns match the expected values precisely.

tests/testthat/test-caretEnsemble.R (10)

25-25: Approved: Stricter equality checks for metrics extraction.

The use of expect_identical ensures that the metrics are not only equal in value but also identical in type and attributes.


29-29: Approved: Stricter equality checks for metrics extraction with standard deviation.

The use of expect_identical ensures that the metrics with standard deviation are not only equal in value but also identical in type and attributes.


73-73: Approved: Stricter equality checks for ensemble predictions.

The use of expect_identical ensures that the number of columns in the predictions is identical.


114-115: Approved: Stricter equality checks for predictions with different predictors.

The use of expect_identical ensures that the number of rows and columns in the predictions is identical.


183-185: Approved: Stricter equality checks for classification model predictions.

The use of expect_identical ensures that the number of rows in the stacked, in-sample, and one-row predictions is identical.


188-190: Approved: Stricter equality checks for classification model predictions.

The use of expect_identical ensures that the number of columns in the stacked, in-sample, and one-row predictions is identical.


236-236: Approved: Stricter equality checks for custom model names.

The use of expect_named ensures that the names of the ensembled models are as expected.


249-251: Approved: Stricter equality checks for custom model predictions.

The use of expect_identical ensures that the number of rows in the stacked, in-sample, and one-row predictions is identical.


254-256: Approved: Stricter equality checks for custom model predictions.

The use of expect_identical ensures that the number of columns in the stacked, in-sample, and one-row predictions is identical.


Line range hint 157-160: Approved: Stricter equality checks for predictions with high excluded class level.

The use of expect_identical ensures that the number of rows and columns in the predictions is identical. The helper function all_finite improves readability and maintainability.

tests/testthat/test-caretStack.R (12)

35-35: Approved: Stricter equality checks for classification model predictions.

The use of expect_identical ensures that the number of rows in the predictions is identical.


134-137: Approved: Stricter equality checks for caretStack object identification.

The use of expect_identical ensures that the identification of caretStack objects is accurate.


157-160: Approved: Stricter equality checks for predictions with high excluded class level.

The use of expect_identical ensures that the number of rows and columns in the predictions is identical. The helper function all_finite improves readability and maintainability.


187-187: Approved: Stricter equality checks for stacking algorithm predictions.

The use of expect_identical ensures that the method of the ensemble model is as expected.


356-357: Approved: Stricter equality checks for predictions with new data.

The use of expect_identical ensures that the number of rows in the predictions is identical.


359-360: Approved: Stricter equality checks for predictions with new data.

The use of expect_identical ensures that the number of columns in the predictions is identical.


368-369: Approved: Stricter equality checks for predictions with new data.

The use of expect_identical ensures that the number of rows in the predictions is identical.


371-372: Approved: Stricter equality checks for predictions with new data.

The use of expect_identical ensures that the number of columns in the predictions is identical.


296-301: Approved: Stricter equality checks for predictions without excluded_class_id.

The use of expect_identical ensures that the number of rows and columns in the predictions is identical and that the predictions are named correctly.


311-312: Approved: Stricter equality checks for caretStack object coercion.

The use of expect_warning ensures that the coercion warning is captured, and the use of expect_identical ensures that the models are correctly coerced to a caretList.


314-315: Approved: Stricter equality checks for caretStack failure conditions.

The use of expect_error ensures that the correct error message is produced when new_X and new_y are not both NULL or both non-NULL.


356-372: Approved: Stricter equality checks for predictions with new data.

The use of expect_identical ensures that the number of rows and columns in the predictions is identical.

R/caretStack.R (8)

42-42: Approved: Improved handling of warnings.

The warning message now suppresses the call stack, improving the user experience.


48-48: Approved: Improved validation of inputs.

The validation ensures that both new_X and new_y are either NULL or non-NULL, improving the robustness of the function.


85-96: Approved: Added caretStack object validation.

The check_caretStack function ensures that the object has the expected structure, improving robustness.


98-110: Approved: Added function to set excluded class ID.

The set_excluded_class_id function centralizes the logic for managing the excluded class ID, improving modularity and readability.


183-183: Approved: Improved caretStack object validation.

The use of check_caretStack ensures that the object is validated early in the execution, improving robustness.


189-189: Approved: Improved handling of excluded class ID.

The use of set_excluded_class_id centralizes the logic for managing the excluded class ID, improving readability and modularity.


247-247: Approved: Improved handling of warnings for standard errors.

The warning message now suppresses the call stack, improving the user experience.


318-318: Approved: Improved output formatting.

The use of toString for formatting the base model names enhances the readability of the printed output.

R/caretList.R (14)

27-27: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


40-40: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


52-56: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


79-79: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


82-84: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


94-95: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


182-182: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


235-235: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


239-239: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


261-261: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


272-272: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


283-283: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


287-288: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


295-295: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.

R/caretEnsemble.R (10)

11-11: Improvement: Cleaner error messages.

Including call. = FALSE in the stop function suppresses the function call in the error message, resulting in cleaner output.


101-103: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


122-122: Enhancement: Use of toString for better readability.

Replacing paste with toString simplifies the code and ensures a more readable output format.


126-126: Enhancement: Use of toString for better readability.

Replacing paste with toString simplifies the code and ensures a more readable output format.


128-129: Enhancement: Use of toString for better readability.

Replacing paste with toString simplifies the code and ensures a more readable output format.


132-132: Enhancement: Use of toString for better readability.

Replacing paste with toString simplifies the code and ensures a more readable output format.


175-175: Enhancement: Use of Map for better readability.

Replacing mapply with Map improves readability and aligns better with the intended use of the functions involved.


Line range hint 213-215:
Enhancement: Stricter assertions with expect_identical.

Using expect_identical ensures both value and type equality, tightening validation criteria.


Line range hint 219-221:
Enhancement: Stricter assertions with expect_identical.

Using expect_identical ensures both value and type equality, tightening validation criteria.


Line range hint 276-279:
Enhancement: Stricter assertions with expect_identical.

Using expect_identical ensures both value and type equality, tightening validation criteria.

tests/testthat/test-helper_functions.R (11)

26-26: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


48-50: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


159-159: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


166-167: Enhancement: Stricter assertions with expect_identical.

Using expect_identical ensures both value and type equality, tightening validation criteria.


173-174: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


213-215: Enhancement: Stricter assertions with expect_identical.

Using expect_identical ensures both value and type equality, tightening validation criteria.


219-221: Enhancement: Stricter assertions with expect_identical.

Using expect_identical ensures both value and type equality, tightening validation criteria.


276-279: Enhancement: Stricter assertions with expect_identical.

Using expect_identical ensures both value and type equality, tightening validation criteria.


358-359: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


364-364: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.


368-369: Enhancement: Use of vapply for type safety.

The replacement of sapply with vapply ensures that the output type is consistent, enhancing type safety and reliability.

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

26-26: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


32-32: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


55-58: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


114-115: Approved: Improved readability and stricter comparison in test case.

Assigning expect_warning to a variable improves readability. Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


157-157: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


168-170: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


239-240: Approved: Improved readability and stricter comparison in test case.

Assigning expect_warning to a variable improves readability. Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


252-252: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


289-290: Approved: Improved readability and stricter comparison in test case.

Assigning expect_warning to a variable improves readability. Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


299-301: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


409-411: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


435-437: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


472-474: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


495-495: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


509-510: Approved: Improved readability and stricter comparison in test case.

Assigning expect_warning to a variable improves readability. Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


517-518: Approved: Improved readability and stricter comparison in test case.

Assigning expect_warning to a variable improves readability. Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


529-530: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


568-571: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


590-590: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


595-597: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


601-603: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


665-665: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.


718-718: Approved: Stricter comparison in test case.

Replacing expect_equal with expect_identical ensures both value and type equality, improving test robustness.

R/caretList.R Outdated Show resolved Hide resolved
@zachmayer zachmayer merged commit 2e98cf3 into main Aug 1, 2024
8 of 9 checks passed
@zachmayer zachmayer deleted the lint branch August 1, 2024 19:04
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