Skip to content

Read .R files from subfolders into .r_script_content for test access#10

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/access-r-files-in-subfolders
Draft

Read .R files from subfolders into .r_script_content for test access#10
Copilot wants to merge 3 commits intomainfrom
copilot/access-r-files-in-subfolders

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

Student repos like dengq25/Lab_8 place R scripts in subfolders (e.g., scripts/01-scrape-page-one.R). The grading workflow had no way to access the content of these files — it only read .Rmd files from the repo root.

Changes

  • New .r_script_content variable: After shared-helper-load.R runs, recursively discovers .R files in the student repo and reads their text content into .r_script_content (character vector, same format as .rmd_content). Files are read, not sourced. .r_script_files holds the discovered paths.

  • Dependency scanning: The "Install student package dependencies" step now scans both .Rmd and .R files (recursively) for library()/require() calls.

  • Recursive file discovery: Changed recursive = FALSETRUE for .Rmd discovery as well, for consistency.

Usage in tests

# Check .R scripts for code patterns (analogous to .rmd_content checks)
test_that("Ex 5: scrape_page function defined in R scripts", {
  skip_if(length(.r_script_content) == 0)
  expect_true(
    any(stringr::str_detect(.r_script_content, "scrape_page\\s*<-\\s*function"))
  )
})
Original prompt

This section details on the original issue you should resolve

<issue_title>access .R files in subfolders</issue_title>
<issue_description>how can I access .R files in subfolders like I do access .rmd files?</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 15, 2026 21:45
- Scan both .Rmd and .R files (recursively) for library/require calls
  to install missing student dependencies
- Source .R files from subfolders into .GlobalEnv before purling/sourcing
  the .Rmd, so objects defined in R scripts are available to tests
- Change file discovery from recursive=FALSE to recursive=TRUE for both
  .Rmd and .R files to find files in subfolders (e.g., scripts/)
- Use append mode for error logging to preserve all errors

Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com>
…to .rmd_content)

- Read .R files from subfolders into .r_script_content (character vector)
  so tests can check code patterns in R scripts separately from Rmd content
- Files are read but NOT sourced/executed
- .r_script_files lists the discovered file paths
- Also scan .R files for library/require calls in dependency installation
- Make file discovery recursive for both .Rmd and .R files

Co-authored-by: smasongarrison <6001608+smasongarrison@users.noreply.github.com>
Copilot AI changed the title [WIP] Access .R files in subfolders like .rmd files Read .R files from subfolders into .r_script_content for test access Mar 15, 2026
Copilot AI requested a review from smasongarrison March 15, 2026 21:50
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.

access .R files in subfolders

2 participants