Skip to main content

copy_frame_attrs

Function copy_frame_attrs 

Source
unsafe fn copy_frame_attrs(from: SEXP, to: SEXP, same_rows: bool)
Expand description

Copy the frame attributes of from onto the new frame to.

Every attribute except names is copied (SexpExt::copy_most_attrib), the rule vctrs::vec_slice(), tibble’s [ and dplyr_reconstruct() follow: class, row.names (verbatim; a producer that changes the rows sets its own afterwards) and anything else a package keeps on the frame, such as a units map or its metadata.

dplyr’s grouping is the exception. A grouped_df / rowwise_df caches its groups in a groups attribute that names the key columns and holds each group’s row indices, so it is copied only while it still describes to: same_rows, and every grouping variable is the very column it was in from (moved, not rebuilt or replaced). Otherwise to loses groups and the grouped_df / rowwise_df class and is the ungrouped frame (a tibble, for a dplyr input), never a grouped frame whose groups are stale.

§Safety

R main thread; from is a data.frame list and to a list whose names are set, protected by the caller.