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
Open
fix auto-print detection on R 3.4/3.5 where sys.calls() returns a promise#7727skitsy24 wants to merge 3 commits intoRdatatable:masterfrom
skitsy24 wants to merge 3 commits intoRdatatable:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
aitap
reviewed
Apr 26, 2026
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 | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.