Skip to content

fix auto-print detection on R 3.4/3.5 where sys.calls() returns a promise#7727

Open
skitsy24 wants to merge 3 commits intoRdatatable:masterfrom
skitsy24:fix7099
Open

fix auto-print detection on R 3.4/3.5 where sys.calls() returns a promise#7727
skitsy24 wants to merge 3 commits intoRdatatable:masterfrom
skitsy24:fix7099

Conversation

@skitsy24
Copy link
Copy Markdown

Closes #7099.

On R 3.4 and 3.5, the top-level call captured via sys.calls() during auto-print is not a direct reference to base::print, but a promise object that evaluates to it. As a result, the existing check:

identical(SYS[[1L]][[1L]], print)

fails, and print.data.table() incorrectly treats auto-print as an explicit print() call. This leads to unintended output in cases where printing should be suppressed (e.g., after := assignments).

Thanks to @aitap for identifying the root cause.

My fix adds a check on whether print() is wrapped in a "promise" to differentiate between the older R versions. If it is a promise, the promise is evaluated, and then checked against print.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.04%. Comparing base (3a45206) to head (194ef2b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7727   +/-   ##
=======================================
  Coverage   99.04%   99.04%           
=======================================
  Files          87       87           
  Lines       17123    17043   -80     
=======================================
- Hits        16959    16880   -79     
+ Misses        164      163    -1     

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

Comment thread R/print.data.table.R Outdated
Comment on lines +40 to +47
} else if (typeof(SYS[[1L]][[1L]]) == "promise") {
# in R 3.4 and R 3.5, auto-print uses a promise to reference base::print due to lazy loading
# safely evaluate promise to get the actual function
evaluated = tryCatch(eval(SYS[[1L]][[1L]]), error = function(e) NULL)
if (identical(evaluated, print)) {
is_print_call = TRUE
}
}
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.

This disappeared in R-3.6.0, right? Let's wrap this branch in # nocov start ... # nocov end and add a # TODO(R>=3.6) comment to remove it once we raise the minimal supported R version.

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.

tests on R 3.4 raises extra warning

2 participants