You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support multiple code folder naming options: "code", "src", "scripts"
Add .find_code_folder_name() helper to detect actual folder name
Update PMProject$create_analysis() to accept code_folder_name parameter
Enhance pm_infer_analysis() to work with any valid code folder name
Update documentation and examples to reflect new flexibility
Diagram Walkthrough
flowchart LR
A["User creates analysis"] -->|code_folder_name param| B["PMProject$create_analysis()"]
B -->|rename folder if needed| C["Analysis with custom code folder"]
D["pm_infer_analysis()"] -->|detect folder name| E[".find_code_folder_name()"]
E -->|validate against options| F["Return analysis object"]
G["Constants"] -->|ANALYSIS_CODE_DIR_OPTIONS| B
G -->|ANALYSIS_CODE_DIR_OPTIONS| E
Fix the create_analysis function by setting a single default value for code_folder_name and explicitly providing the choices to match.arg to ensure correct argument matching.
Why: The suggestion fixes a bug in the use of match.arg which would behave unexpectedly when the code_folder_name argument is not provided, making the function more robust and correct.
Medium
Handle ambiguous code folder detection
Modify .find_code_folder_name to detect if multiple valid code folders exist (e.g., code and src) and throw an error to prevent ambiguous behavior, instead of just returning the first one found.
.find_code_folder_name <- function(analysis_path) {
+ existing_options <- c()
for (option in constants$ANALYSIS_CODE_DIR_OPTIONS) {
- if (dir.exists(file.path(analysis_path, option))){- return(option)+ if (dir.exists(file.path(analysis_path, option))) {+ existing_options <- c(existing_options, option)
}
}
- stop(paste("Failed to find code folder with valid name for analysis at", analysis_path))+ if (length(existing_options) == 1) {+ return(existing_options)+ }++ if (length(existing_options) == 0) {+ stop(paste("Failed to find code folder with valid name for analysis at", analysis_path))+ }++ stop(+ paste(+ "Found multiple valid code folders for analysis at",+ analysis_path,+ ":",+ paste(existing_options, collapse = ", ")+ )+ )
}
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies an edge case where multiple valid code folders could exist, leading to ambiguity, and proposes a more robust check to ensure exactly one is present.
Medium
Validate code folder rename success
Add a check for the return value of file.rename() and throw an error if the operation fails to rename the code folder.
if (code_folder_name != "code") {
- file.rename(+ success <- file.rename(
from = file.path(analysis_path, "code"),
to = file.path(analysis_path, code_folder_name)
)
+ if (!success) {+ stop(sprintf("Failed to rename code folder to '%s'", code_folder_name))+ }
}
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: This suggestion improves error handling by verifying the success of the file.rename operation, preventing silent failures and making the function more robust.
Medium
General
Include valid options in error
Improve the error message in .find_code_folder_name to include the list of valid folder names when no valid folder is found.
-stop(paste("Failed to find code folder with valid name for analysis at", analysis_path))+stop(sprintf(+ "Failed to find code folder in '%s'; expected one of: %s",+ analysis_path,+ paste(constants$ANALYSIS_CODE_DIR_OPTIONS, collapse = ", ")+))
Apply / Chat
Suggestion importance[1-10]: 5
__
Why: This suggestion improves the user experience by providing a more informative error message that lists the valid options for the code folder name.
Low
More
Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.
❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Implements the request by @ cristian
PR Type
Enhancement
Description
Support multiple code folder naming options: "code", "src", "scripts"
Add
.find_code_folder_name()helper to detect actual folder nameUpdate
PMProject$create_analysis()to acceptcode_folder_nameparameterEnhance
pm_infer_analysis()to work with any valid code folder nameUpdate documentation and examples to reflect new flexibility
Diagram Walkthrough
File Walkthrough
3 files
Add code folder naming options constantAdd code_folder_name parameter to create_analysisImplement code folder detection and flexible naming1 files
Add tests for different code folder names1 files
Bump version to 0.1.1016 files
Document new code folder naming featureUpdate changelog with new featuresRegenerate changelog HTML documentationUpdate PMProject documentation with new parameterAdd documentation for helper functionUpdate pm_infer_analysis documentationRegenerate PMProject reference documentationUpdate PMProject markdown referenceGenerate new helper function reference pageGenerate new helper function markdown referenceRegenerate pm_infer_analysis reference pageUpdate pm_infer_analysis markdown referenceUpdate getting started guide with new featureUpdate getting started markdown with examplesUpdate vignette with code folder naming examplesAdd template project README with package reference39 files