Skip to content

Conversation

venom1204
Copy link
Contributor

closes #7219

This PR enhances rowwise() to detect all non-atomic, non-list column values (e.g., language objects, expressions, pairlists, environments, S4 objects) instead of only functions. It adds a clear error message with the offending column name and type, plus guidance to wrap values in list(...) if intended. Includes updated tests for both allowed and rejected cases.

hi @tdhock @MichaelChirico @aitap can you please have a look when you got time .

thanks.

Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (a837dc9) to head (dafc34f).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7250   +/-   ##
=======================================
  Coverage   99.01%   99.02%           
=======================================
  Files          81       81           
  Lines       15503    15517   +14     
=======================================
+ Hits        15351    15365   +14     
  Misses        152      152           

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

Copy link

github-actions bot commented Aug 12, 2025

No obvious timing issues in HEAD=issue_7219
Comparison Plot

Generated via commit dafc34f

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 2 minutes and 46 seconds
Installing different package versions 20 seconds
Running and plotting the test cases 2 minutes and 40 seconds

R/rowwiseDT.R Outdated
nrows = length(body) %/% ncols
if (length(body) != nrows * ncols)
stopf("There are %d columns but the number of cells is %d, which is not an integer multiple of the columns", ncols, length(body))

Copy link
Member

Choose a reason for hiding this comment

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

please undo addition of empty lines

Copy link
Member

@tdhock tdhock left a comment

Choose a reason for hiding this comment

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

please fix

@venom1204 venom1204 requested a review from tdhock August 15, 2025 07:06
@venom1204
Copy link
Contributor Author

hi @tdhock I did the modifications can you please have a look when you got time.
thanks

R/rowwiseDT.R Outdated
stopf("There are %d columns but the number of cells is %d, which is not an integer multiple of the columns", ncols, length(body))
is_problematic = vapply(
body,
function(v) !is.atomic(v) && !is.null(v) && typeof(v) != "list",
Copy link
Member

Choose a reason for hiding this comment

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

is this check really what @aitap wrote about catering for that is.atomic(NULL)=TRUE on older R versions?

it should also be faster to check !(is.atomic(v) || is.null(v) || typeof(v) == "list")

Note that we have our internal versions of vapply e.g. vapply_1b

@venom1204 venom1204 requested a review from ben-schwen August 25, 2025 10:01
R/rowwiseDT.R Outdated
first_problem_idx = which(is_problematic)[1L]
col_idx = (first_problem_idx - 1L) %% ncols + 1L
col_name = header[col_idx]
obj_type = typeof(body[[first_problem_idx]])
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if typeof is the right choice here. For the problem raised in #7219 class would be a better choice since class would be "function" but typeof would be still "closure".

R/rowwiseDT.R Outdated
col_name = header[col_idx]
obj_type = typeof(body[[first_problem_idx]])
stopf(
"In column '%s', received an object of type '%s'.\nComplex objects (like functions, models, etc.) must be wrapped in list() to be stored in a data.table column.\nPlease use `list(...)` for this value.",
Copy link
Member

Choose a reason for hiding this comment

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

Is this really true? Many models are indeed lists, e.g. lm(mpg~., data=mtcars).

Other thing on top of my head would be expressions which we do not fully support. Storing environments into a data.table seems uncommon to me.

Copy link
Member

@ben-schwen ben-schwen left a comment

Choose a reason for hiding this comment

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

We also still miss a NEWS item!

@venom1204 venom1204 requested a review from ben-schwen August 30, 2025 11:43
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.

rowwiseDT with column of functions
3 participants