Skip to content

vec_proxy() should always call vec_data() on the final output #2129

@DavisVaughan

Description

@DavisVaughan

@lionel- and I have determined that vec_data() (or vec_unstructure()) is actual a critical vctrs primitive. It's purpose is:

vec_data() returns the native form of x according to the vctrs type system.

Where "native" is defined as retaining only the "core" attributes of x that are absolutely required for it to function. The core attributes are defined as:

  • For data frames:
    • row.names (vec-names)
    • names (column names)
    • class = "data.frame"
  • For arrays:
    • dimnames (vec-names and shape-names)
    • dim (size and shape)
  • For anything else:
    • names (vec-names)

Our thoughts are that your vec_proxy() method should return a C compatible form of your data, i.e. if all S3 dispatch was ignored and we looked only at the native type of that object, it should be compatible with the vctrs system.

Our vec_proxy() generic will be in charge of taking that proxy result and calling vec_data() on it. This makes vec_proxy() itself more informative if you're looking at the output as a user.

Note that calling vec_data() is mostly unnecessary when we manipulate these objects at the C level, and will only waste time, so we intend to have both vec_proxy() and vec_proxy_unsafe() from C level, where the latter does not call vec_data() on the result. The result of vec_proxy_unsafe() may have extraneous attributes attached to it, but we as the caller promise that that won't matter for what we are doing with the proxy.

Note that a C level vec_proxy() will be useful in some cases. Like with vec_ptype(), where we plan to replace the vec_slice(x, 0) S3 fallback path with the following set of operations:

  • proxy = vec_proxy(x): Important that this strips all classes
  • ptype = vec_ptype(proxy): Re-call vec_ptype() on the native object
  • vec_restore(ptype, x): Restore back to original type

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions