Simplify Ryaml_yoink() and preserve class attributes so handlers work with column.major = FALSE#164
Open
Simplify Ryaml_yoink() and preserve class attributes so handlers work with column.major = FALSE#164
Ryaml_yoink() and preserve class attributes so handlers work with column.major = FALSE#164Conversation
In Ryaml_yoink(), use copyMostAttrib() to preserve class attributes when extracting single elements from data frame columns for row-major output. This ensures Date and POSIXt handlers are triggered correctly. Fixes #161 Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix unexpected interaction between column.major and Date handlers
Preserve class attributes in Feb 28, 2026
Ryaml_yoink() so handlers work with column.major = FALSE
Member
|
@copilot Why are factors treated specially? Add tests. |
…trib Remove the factor-specific code path that converted factors to STRSXP in Ryaml_yoink(). Instead, always copy the integer value and call copyMostAttrib() unconditionally. The existing emit_factor() in emit_object() handles factor resolution correctly. This ensures factor handlers work with column.major = FALSE, just like Date and POSIXt handlers. Added tests for factor columns. Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Author
Good point — there's no reason to special-case factors. Removed the factor-specific code path entirely in |
Copilot
AI
changed the title
Preserve class attributes in
Simplify Feb 28, 2026
Ryaml_yoink() so handlers work with column.major = FALSERyaml_yoink() and preserve class attributes so handlers work with column.major = FALSE
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.
Ryaml_yoink()extracts single elements from data frame columns for row-major output but strips class attributes, so Date/POSIXt/factor handlers never match.Changes
src/r_emit.c: SimplifyRyaml_yoink()by removing the factor-specific code path that converted factors from INTSXP to STRSXP inline. Instead, always extract the raw value and callcopyMostAttrib(s_vec, s_tmp)unconditionally, preserving class,tzone, levels, and other attributes on extracted elements. For factors, the existingemit_factor()inemit_object()handles level resolution correctly on the preserved single-element factor.tests/testthat/test-as_yaml.R: Add tests forDate,POSIXct, and factor columns withcolumn.major = FALSE, including tests with custom handlers.Original prompt
This section details on the original issue you should resolve
<issue_title>Unexpected interaction between
column.majorand Datehandlersinas.yaml()</issue_title><issue_description>In
as.yaml(), settingcolumn.major=FALSEappears to prevent the application of Datehandlers. For a while, I thought I was specifying my handler functions incorrectly, but I don't believe that is the case. I used these references for the handlers:I've included a minimal example showing the difference in date handling when
column.major=TRUE(default) vs. whencolumn.major=FALSE. This interaction doesn't appear when using theverbatim_logicalhandler, making the Date behaviour entirely unexpected.Created on 2024-03-18 with reprex v2.0.2
Session info