Skip to content

Avoid shadowing message in autoprint tests - #7446

Merged
MichaelChirico merged 5 commits into
masterfrom
test-autoprint-suppress-messages
Dec 8, 2025
Merged

MichaelChirico merged 5 commits into
masterfrom
test-autoprint-suppress-messages

Conversation

@aitap

@aitap aitap commented Dec 5, 2025

Copy link
Copy Markdown
Member

R-devel has introduced base::`%notin%`, which data.table now shadows, which shows up in the "golden" output test:

  Comparing ‘autoprint.Rout’ to ‘autoprint.Rout.save’ ...4,10d3
<
< Attaching package: 'data.table'
<
< The following object is masked from 'package:base':
<
<     %notin%
<

Use suppressPackageStartupMessages(...) in the test to avoid the message.

@TysonStanley, I think this is needed for cherry-picking to avoid an extra NOTE.

  Comparing ‘autoprint.Rout’ to ‘autoprint.Rout.save’ ...4,10d3
<
< Attaching package: 'data.table'
<
< The following object is masked from 'package:base':
<
<     %notin%
<
@aitap
aitap requested a review from MichaelChirico as a code owner December 5, 2025 16:11
@codecov

codecov Bot commented Dec 5, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.07%. Comparing base (3c044ce) to head (1fabe00).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7446   +/-   ##
=======================================
  Coverage   99.07%   99.07%           
=======================================
  Files          85       85           
  Lines       16609    16610    +1     
=======================================
+ Hits        16455    16456    +1     
  Misses        154      154           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@MichaelChirico

Copy link
Copy Markdown
Member

is the definition identical? if so we should start a deprecation cycle too

@aitap

aitap commented Dec 5, 2025 •

Copy link
Copy Markdown
Member Author

Ours might be faster when both arguments are character vectors; otherwise identical:

> `%notin%`
function (x, table)
match(x, table, nomatch = 0L) == 0L
<bytecode: 0x563bba77e7f8>
<environment: namespace:base>
> data.table::`%notin%`
function (x, table)
{
    if (is.character(x) && is.character(table)) {
        .Call(Cnotchin, x, table)
    }
    else {
        match(x, table, nomatch = 0L) == 0L
    }
}
<bytecode: 0x563bbab3aea0>
<environment: namespace:data.table>

@jangorecki

Copy link
Copy Markdown
Member

I would definitely aim for deprecation, I don't think differences will be that big

Comment thread tests/autoprint.R Outdated
@@ -1,4 +1,4 @@
require(data.table)
suppressPackageStartupMessages(require(data.table))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR I'd prefer require(data.table, exclude="%notin%"), however that's from 3.6.0 (r76248):

r-devel/r-svn@c220e47

Maybe just require(data.table, warn.conflicts=!exists("%notin%", "package:base")) is the most concise way to narrowly skip for only this issue?

With blanket suppress* I worry about missing other such issues in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very concise compared to dynamic call manipulation and testing for 'exclude' %in% names(formals(require))), thank you!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, still not ideal, as it means all future versions turn off conflict warnings. I guess it doesn't matter much for this test anyway -- we could just statically set it to FALSE?

MichaelChirico and others added 2 commits December 5, 2025 21:53
Unfortunately, require(data.table, exclude="%notin") requires R >= 3.6.
@aitap

aitap commented Dec 6, 2025 •

Copy link
Copy Markdown
Member Author

Three CRAN packages import %notin%: bruceR, tidyfst, and weatherOz; the first two for re-exporting. Any clever tricks (à la cedta?) we might use so that interactive users who would get base::`%notin%` anyway will not get penalised? I see that some packages (e.g. backports) export objects conditionally on R version. Should we try to eventually use if (getRversion() < "4.6.0")) export("%notin%") and similarly emit deprecation warnings only on R ≥ 4.6.0?

@MichaelChirico

Copy link
Copy Markdown
Member

An if() in the NAMESPACE might work... let's explore the full implications as a follow-up issue: #7453

Comment thread tests/autoprint.R Outdated
Comment thread tests/autoprint.Rout.save Outdated
@MichaelChirico
MichaelChirico merged commit 585ab23 into master Dec 8, 2025
11 checks passed
@MichaelChirico
MichaelChirico deleted the test-autoprint-suppress-messages branch December 8, 2025 03:19
aitap added a commit that referenced this pull request Dec 10, 2025
* Avoid shadowing message in autoprint tests

  Comparing ‘autoprint.Rout’ to ‘autoprint.Rout.save’ ...4,10d3
<
< Attaching package: 'data.table'
<
< The following object is masked from 'package:base':
<
<     %notin%
<

* Suppress conflict messages on new enough R-devel

Unfortunately, require(data.table, exclude="%notin") requires R >= 3.6.

* Just disable warn.conflicts for now

* link issue directly

* link issue directly

---------

Co-authored-by: Michael Chirico <[email protected]>
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.

3 participants