Learn R Programming

cheapr (version 1.2.0)

reconstruct: Reconstruct an object from a template

Description

Reconstruct an object from a template

Usage

reconstruct(x, template, ...)

# S3 method for data.frame reconstruct(x, template, shallow_copy = TRUE, ...)

# S3 method for data.table reconstruct(x, template, shallow_copy = TRUE, ...)

Value

An object similar to template.

Arguments

x

An object in which carefully selected attributes will be copied into from template.

template

A template object used to copy attributes into x.

...

Further arguments passed onto methods.

shallow_copy

Should x be shallow copied before reconstructing? Default is TRUE.

Details

In R attributes are difficult to work with. One big reason for this is that attributes may or may not be independent of the data. Date vectors for example have attributes completely independent of the data and hence if the attributes are removed at any point, they can easily be re-added without any calculations. Factors have almost data-independent attributes with an exception being when factors are combined. In some cases it is not possible to reconstruct attributes from the data alone.

You can add your own reconstruct method for an object not covered by the methods here.