Skip to content

Fix file asset access issues on CRAN - DEM.tif excluded from package build#136

Closed
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-file-asset-access-issues
Closed

Fix file asset access issues on CRAN - DEM.tif excluded from package build#136
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-file-asset-access-issues

Conversation

Copy link
Copy Markdown

Copilot AI commented Oct 18, 2025

Problem

CRAN check failures were occurring with the error Error: File () does not exist in test-wbt_source.R. The issue statement suggested this was related to recent changes in sample_dem_data() behavior and the read-only filesystem on CRAN check servers.

Root Cause

The actual root cause was in .Rbuildignore: the pattern ^.*\.tif$ was excluding all .tif files from the package build, including the essential sample data file inst/extdata/DEM.tif. This caused the file to be completely missing from the package tarball distributed to CRAN, resulting in sample_dem_data() returning an empty string and subsequent test failures.

Changes Made

1. Fixed .Rbuildignore pattern (Critical)

Changed: ^.*\.tif$^[^/]*\.tif$

The original pattern matched any path ending in .tif, including inst/extdata/DEM.tif. The new pattern only matches .tif files in the package root directory, ensuring that sample data files in inst/extdata/ are properly included in package builds.

2. Added defensive test guards

Added skip_if(f == "") checks in tests/testthat/test-wbt_source.R after calls to sample_dem_data() and sample_soils_data(). This makes tests gracefully skip when sample data is unavailable, consistent with the pattern already used in all other test files in the package.

3. Enhanced sample_dem_data() robustness

Improved the function to handle read-only filesystem scenarios (common on CRAN check servers):

  • Detects if the package installation directory is writable using file.access()
  • Falls back to tempdir() when the package directory is read-only
  • Better error handling with explicit download result checking
  • More informative code comments explaining the logic

Testing

These changes ensure that:

  • ✅ The DEM.tif file is included in package builds and available on CRAN
  • ✅ Tests skip gracefully if sample data is missing for any reason
  • ✅ Downloads work even on read-only package installations
  • ✅ Backward compatibility is maintained for all existing functionality

Fixes the CRAN check errors reported by Kurt Hornik on the Debian check systems.

Original prompt

This section details on the original issue you should resolve

<issue_title>bug: file asset access issues on CRAN</issue_title>
<issue_description>Need to resolve the following errors and warnings on the check server. Possibly related to recent changes in behavior of sample_dem_data(), which I thought would be safe to do. If not that need to assess where this regression came from. Kurt Hornik states "check problems on the Debian systems may be caused by attempts to write to the user library to which all packages get installed before
checking (and which now is remounted read-only for checking)."

The WBT tool calls should fail gracefully in absence of the WBT binary. There might need to be some tests skipped but also the internal file handling should be reviewed to make sure we are conforming with CRAN guidelines regarding the tools user directory folder. I think the issue is actually with the missing Geotiff data file, not the WBT binary, despite the sh stdout in the check log.

using R Under development (unstable) (2025-10-15 r88920)
using platform: x86_64-pc-linux-gnu
R was compiled by
    Debian clang version 19.1.7 (7)
    Debian flang-new version 19.1.7 (7)
running under: Debian GNU/Linux forky/sid
using session charset: UTF-8
checking for file ‘whitebox/DESCRIPTION’ ... OK
checking extension type ... Package
this is package ‘whitebox’ version ‘2.4.2’
package encoding: UTF-8
checking CRAN incoming feasibility ... [5s/7s] OK
checking package namespace information ... OK
checking package dependencies ... OK
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 ‘whitebox’ can be installed ... OK
See the install log for details.
checking package directory ... OK
checking for future file timestamps ... 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 ... [0s/1s] OK
checking whether the package can be loaded with stated dependencies ... [0s/0s] OK
checking whether the package can be unloaded cleanly ... [0s/0s] OK
checking whether the namespace can be loaded with stated dependencies ... [0s/0s] OK
checking whether the namespace can be unloaded cleanly ... [0s/0s] OK
checking loading without being on the library search path ... [0s/1s] OK
checking whether startup messages can be suppressed ... [0s/1s] 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 ... [47s/62s] OK
checking Rd files ... [4s/5s] 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 contents of ‘data’ directory ... OK
checking data for non-ASCII characters ... [0s/1s] OK
checking LazyData ... OK
checking data for ASCII and uncompressed saves ... OK
checking installed files from ‘inst/doc’ ... OK
checking files in ‘vignettes’ ... OK
checking examples ... [0s/1s] OK
checking for unstated dependencies in ‘tests’ ... OK
checking tests ... [11s/16s] ERROR
  Running ‘testthat.R’ [10s/16s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > 
  > library(whitebox)
  > # whitebox:::wbt_rust_backtrace('1')
  > 
  > if (requireNamespace("testthat")) {
  +   library(testthat)
  +   test_check("whitebox")
  + }
  Loading required namespace: testthat
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-regular-hornik/data/R/whitebox/WBT/whitebox_tools: not found
  sh: 1: /home/hornik/tmp/scratch/check-CRAN-re...

</details>

Fixes opengeos/whiteboxR#135

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

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey3.medallia.com/?EAHeSx-AP01bZqG0Ld9QLQ) to start the survey.

Copilot AI self-assigned this Oct 18, 2025
Copilot AI and others added 2 commits October 18, 2025 18:34
- Add skip_if checks in test-wbt_source.R to handle missing sample data
- Improve sample_dem_data() to use tempdir() when package dir is read-only

Co-authored-by: brownag <20842828+brownag@users.noreply.github.com>
The pattern ^.*\.tif$ was excluding ALL .tif files including the required
sample data file inst/extdata/DEM.tif. Changed to ^[^/]*\.tif$ to only
exclude .tif files in the package root directory.

Co-authored-by: brownag <20842828+brownag@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix file asset access issues on CRAN Fix file asset access issues on CRAN - DEM.tif excluded from package build Oct 18, 2025
Copilot AI requested a review from brownag October 18, 2025 18:39
@brownag
Copy link
Copy Markdown
Member

brownag commented Oct 18, 2025

This is a reasonable solution. I didn't see this PR, was expecting a comment in the issue (I dont know why). Kicking the tires on possibly using the Copilot features more.

I am pleased to see we arrived at similar, but non-identical solutions. I want to only include inst/extdata/DEM.tif, nothing more. So #137 with the explicit negative lookahead in .Rbuildignore will supersede this. We also both defensively added skips to the tests for possible missing files, which is good. I don't think sample_dem_data() will return empty values now, but good to have a fallback in case we change the internal logic some day. When I get called out like this by CRAN I am hesitant to just skip the offending tests... 👼 but at the same time, a lot of package features cannot be fully tested on CRAN, so it is not that big of a deal.

If you have any additional comments, make them in review of #137. I think we can safely ignore the other missing file output from the check logs... that is functioning as intended, but a bit verbose on linux

@brownag brownag closed this Oct 18, 2025
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