Skip to content

Fix conditional usage of suggested packages (fs, ggalign)#62

Merged
ShixiangWang merged 5 commits intomainfrom
copilot/fix-package-check-issue
Jan 18, 2026
Merged

Fix conditional usage of suggested packages (fs, ggalign)#62
ShixiangWang merged 5 commits intomainfrom
copilot/fix-package-check-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 18, 2026

CRAN check failures due to unconditional usage of packages in Suggests. Per Writing R Extensions, suggested packages must be used conditionally with requireNamespace() checks.

Changes

  • R/03-accessors.R: Wrapped fs::is_file() calls with requireNamespace("fs", quietly = TRUE) checks
  • R/02-pipeline.R: Added conditional checks for all fs:: functions with base R fallbacks:
    • fs::path_temp()tempdir()
    • fs::dir_create()dir.create(..., recursive = TRUE, showWarnings = FALSE)
    • fs::path()file.path() with paste0() for extensions
    • Removed fs from rlang::check_installed() since fallbacks are provided
  • R/04-show.R: Wrapped ggalign::align_plots() with conditional check, falling back to list(plots = valid_plots) when unavailable

Example

Before:

fs::dir_create(md_path)  # Error if fs not installed

After:

if (requireNamespace("fs", quietly = TRUE)) {
  fs::dir_create(md_path)
} else {
  dir.create(md_path, showWarnings = FALSE, recursive = TRUE)
}

Both ggalign::alignpatches objects and the fallback list provide consistent $plots accessor for tests.

Original prompt

This section details on the original issue you should resolve

<issue_title>package check issue</issue_title>
<issue_description>Packages in Suggests should be used conditionally: see 'Writing R Extensions'

   if (requireNamespace("rgl", quietly = TRUE)) {
      rgl::plot3d(...)
   } else {
      ## do something else not involving rgl.
   }

Current check issue:

* using log directory ‘/data/gannet/ripley/R/packages/tests-Suggests/bregr.Rcheck’
* using R Under development (unstable) (2026-01-16 r89305)
* using platform: x86_64-pc-linux-gnu
* R was compiled by
    gcc (GCC) 15.1.1 20250521 (Red Hat 15.1.1-2)
    GNU Fortran (GCC) 15.1.1 20250521 (Red Hat 15.1.1-2)
* running under: Fedora Linux 42 (Workstation Edition)
* using session charset: UTF-8
* using option ‘--no-stop-on-test-error’
* checking for file ‘bregr/DESCRIPTION’ ... OK
* this is package ‘bregr’ version ‘1.3.1’
* package encoding: UTF-8
* checking package namespace information ... OK
* checking package dependencies ... INFO
Package suggested but not available for checking: ‘qs’
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘bregr’ can be installed ... [24s/31s] OK
* checking package directory ... OK
* checking ‘build’ directory ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking code files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking whether startup messages can be suppressed ... OK
* checking use of S3 registration ... OK
* checking dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... [39s/43s] OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd line widths ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking installed files from ‘inst/doc’ ... OK
* checking files in ‘vignettes’ ... OK
* checking examples ... ERROR
Running examples in ‘bregr-Ex.R’ failed
The error most likely occurred in:

> ### Name: accessors
> ### Title: Accessor functions for 'breg' objects
> ### Aliases: accessors br_get_data br_get_y br_get_x br_get_n_x br_get_x2
> ###   br_get_n_x2 br_get_group_by br_get_config br_get_models br_get_model
> ###   br_get_model_names br_rename_models br_get_results
> 
> ### ** Examples
> 
> m <- br_pipeline(mtcars,
+   y = "mpg",
+   x = colnames(mtcars)[2:4],
+   x2 = "vs",
+   method = "gaussian"
+ )
Error in loadNamespace(x) : there is no package called ‘fs’
Calls: br_pipeline ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
  Running ‘testthat.R’ [129s/154s]
 [130s/154s] ERROR
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > # This file is part of the standard setup for testthat.
  > # It is recommended that you do not modify it.
  > #
  > # Where should you do additional test configuration?
  > # Learn more about the roles of various files in:
  > # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
  > # * https://testthat.r-lib.org/articles/special-files.html
  > 
  > library(testthat)
  > library(bregr)
  Welcome to 'bregr' package!
  =======================================================================
  You are using bregr version 1.3.1
  
  Project home : https://github.com/WangLabCSU/bregr
  Documentation: https://wanglabcsu.github.io/bregr/
  Cite as      : https://doi.org/10.1002/mdr2.70028
    Wang, S., Peng, Y., Shu, C., Wang, C., Yang, Y., Zhao, Y., Cui, Y., Hu, D. and Zhou, J.-G. (2025),
    bregr: An R Package for Streamlined Batch Processing and Visualization of Biomedical Regression Models. Med Research.
  =======================================================================
                   
  > 
  > test_check("bregr")
  filtered variables: "x2" and "x3"
  filtered variables: "x2"
  Pre-filtering...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes WangLabCSU/bregr#61

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 3 commits January 18, 2026 03:37
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix package check issue by using namespaces conditionally Fix conditional usage of suggested packages (fs, ggalign) Jan 18, 2026
Copilot AI requested a review from ShixiangWang January 18, 2026 03:52
Addressed issues reported by devtools::check with _R_CHECK_DEPENDS_ONLY_ by updating function signatures for style consistency, wrapping examples and tests in requireNamespace checks for optional dependencies, and correcting documentation. Also updated package description and test line numbers to reflect these changes.
@ShixiangWang ShixiangWang marked this pull request as ready for review January 18, 2026 05:31
@ShixiangWang ShixiangWang merged commit 71d3999 into main Jan 18, 2026
5 of 6 checks passed
@ShixiangWang ShixiangWang deleted the copilot/fix-package-check-issue branch January 18, 2026 05:37
ShixiangWang added a commit that referenced this pull request Jan 18, 2026
* Initial plan

* Add br_compare_models and br_show_forest_comparison functions

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>

* Add comprehensive tests for comparison functionality

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>

* Add comparison example to README

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>

* Fix test failure and tidyselect deprecation warnings

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>

* Refactor compare functions and remove README.html

Refactored R/08-compare.R for improved code clarity and consistency, mainly adjusting whitespace and minor formatting. Deleted the generated README.html file. Updated related test files to align with the refactored code.

* Replace qs with qs2 in dependencies and accessors

Updated the DESCRIPTION file to suggest 'qs2' instead of 'qs'. Modified R/03-accessors.R to use 'qs2::qread' and check for 'qs2' package instead of 'qs'. This ensures compatibility with the 'qs2' package for model reading functionality.

* Update 02-pipeline.R

* Replace deprecated qs package with qs2

Updated code to use the qs2 package instead of the deprecated qs package. Changed function calls from qs2::qsave/qread to qs2::qs_save/qs_read in pipeline and accessor functions. Updated NEWS.md to document the change.

* Increment version number to 1.4.0

* Update _pkgdown.yml

* Update 08-compare.R

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: Shixiang Wang (王诗翔) <wangshx@csu.edu.cn>
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.

2 participants