Skip to content

Comments

Add different options for code folder#20

Merged
Alon-Alexander merged 1 commit intomainfrom
feature/different_source_folder_name
Feb 6, 2026
Merged

Add different options for code folder#20
Alon-Alexander merged 1 commit intomainfrom
feature/different_source_folder_name

Conversation

@Alon-Alexander
Copy link
Owner

@Alon-Alexander Alon-Alexander commented Feb 6, 2026

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 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
Loading

File Walkthrough

Relevant files
Enhancement
3 files
constants.R
Add code folder naming options constant                                   
+1/-0     
project.R
Add code_folder_name parameter to create_analysis               
+14/-1   
analysis.R
Implement code folder detection and flexible naming           
+28/-3   
Tests
1 files
test_analysis.R
Add tests for different code folder names                               
+50/-0   
Configuration changes
1 files
DESCRIPTION
Bump version to 0.1.10                                                                     
+1/-1     
Documentation
16 files
NEWS.md
Document new code folder naming feature                                   
+7/-0     
index.md
Update changelog with new features                                             
+8/-0     
index.html
Regenerate changelog HTML documentation                                   
+9/-1     
PMProject.Rd
Update PMProject documentation with new parameter               
+7/-1     
dot-find_code_folder_name.Rd
Add documentation for helper function                                       
+16/-0   
pm_infer_analysis.Rd
Update pm_infer_analysis documentation                                     
+1/-1     
PMProject.html
Regenerate PMProject reference documentation                         
+15/-7   
PMProject.md
Update PMProject markdown reference                                           
+14/-6   
dot-find_code_folder_name.html
Generate new helper function reference page                           
+82/-0   
dot-find_code_folder_name.md
Generate new helper function markdown reference                   
+16/-0   
pm_infer_analysis.html
Regenerate pm_infer_analysis reference page                           
+10/-10 
pm_infer_analysis.md
Update pm_infer_analysis markdown reference                           
+7/-7     
getting-started.html
Update getting started guide with new feature                       
+17/-14 
getting-started.md
Update getting started markdown with examples                       
+15/-12 
getting-started.Rmd
Update vignette with code folder naming examples                 
+4/-1     
README.md
Add template project README with package reference             
+8/-0     
Additional files
39 files
404.html +1/-1     
LICENSE.html +1/-1     
file-formats.html +3/-3     
file-formats.md +1/-1     
index.html +1/-1     
input-definitions.html +2/-2     
slurm-integration.html +2/-2     
authors.html +3/-3     
authors.md +2/-2     
index.html +1/-1     
pkgdown.yml +1/-1     
PMAnalysis.html +6/-5     
PMAnalysis.md +7/-4     
PMData.html +1/-1     
PMSlurmRun.html +1/-1     
dot-cancel_slurm_job.html +1/-1     
dot-check_missing_entries.html +1/-1     
dot-check_missing_files.html +1/-1     
dot-check_slurm_job_done.html +1/-1     
dot-check_slurm_job_success.html +1/-1     
dot-extract_input_ids.html +1/-1     
dot-format_validation_error.html +1/-1     
dot-get_slurm_job_error.html +1/-1     
dot-submit_slurm_job_with_env.html +1/-1     
dot-validate_input_fields.html +1/-1     
dot-validate_input_files.html +1/-1     
dot-validate_inputs_schema.html +1/-1     
dot-validate_local_inputs_schema.html +1/-1     
index.html +1/-1     
is_slurm_available.html +1/-1     
pm_create_project.html +2/-2     
pm_create_project.md +1/-1     
pm_project.html +2/-2     
pm_project.md +1/-1     
pm_read_file.html +1/-1     
pm_write_file.html +1/-1     
search.json +1/-1     
sitemap.xml +1/-0     
test_slurm.R +0/-2     

@Alon-Alexander Alon-Alexander self-assigned this Feb 6, 2026
@qodo-free-for-open-source-projects

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Use correct default for code_folder_name

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.

R/project.R [352-353]

-create_analysis = function(name, code_folder_name = constants$ANALYSIS_CODE_DIR_OPTIONS) {
-  code_folder_name <- match.arg(code_folder_name)
+create_analysis = function(name, code_folder_name = constants$ANALYSIS_CODE_DIR_OPTIONS[1]) {
+  code_folder_name <- match.arg(code_folder_name, constants$ANALYSIS_CODE_DIR_OPTIONS)
  • Apply / Chat
Suggestion importance[1-10]: 8

__

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.

R/analysis.R [663-671]

 .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.

R/project.R [386-391]

 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.

R/analysis.R [670]

-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.

@Alon-Alexander Alon-Alexander merged commit 35f1cf3 into main Feb 6, 2026
11 checks passed
@Alon-Alexander Alon-Alexander deleted the feature/different_source_folder_name branch February 6, 2026 11:54
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
R/analysis.R 88.88% 1 Missing ⚠️
Files with missing lines Coverage Δ
R/constants.R 100.00% <ø> (ø)
R/project.R 93.97% <100.00%> (-0.59%) ⬇️
R/analysis.R 54.94% <88.88%> (+0.53%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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