% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-s3.R
\name{as_tidyped}
\alias{as_tidyped}
\title{Restore the tidyped class to a manipulated pedigree}
\usage{
as_tidyped(x)
}
\arguments{
\item{x}{A \code{data.table} or \code{data.frame} that was previously a
tidyped object. It must still contain the core columns: \code{Ind},
\code{Sire}, \code{Dam}, \code{Sex}, \code{Gen}, \code{IndNum},
\code{SireNum}, \code{DamNum}.}
}
\value{
A \code{tidyped} object.
}
\description{
Rapidly restores the \code{tidyped} class to a \code{data.table} or
\code{data.frame} that was previously processed by \code{\link{tidyped}()}
but lost its class attributes due to data manipulation.
}
\details{
This is a lightweight operation that only checks for the required columns
and re-attaches the class---it does \strong{not} re-run the full pedigree
sorting, generation inference, or loop detection.


This helper is intended for objects that still contain the core pedigree
columns and numeric indices, but no longer inherit from \code{tidyped}.
A common reproducible case is \code{rbind()} on two \code{tidyped}
fragments, which typically returns a plain \code{data.table}. Converting a
\code{tidyped} object to a plain \code{data.frame} and then subsetting it
also drops the class.

Some operations, such as \code{merge()} or certain dplyr workflows, may or
may not preserve the \code{tidyped} class depending on the versions of
\pkg{data.table}, \pkg{dplyr}, and the exact method dispatch path used in
the current R session. Therefore, \code{as_tidyped()} should be viewed as a
safe recovery helper rather than something only needed after one specific
verb.

Typical class-loss scenarios include:
\itemize{
  \item \code{rbind(tped1, tped2)} --- often returns plain \code{data.table}
  \item \code{as.data.frame(tped)[rows, ]} --- returns plain \code{data.frame}
  \item manual class removal or serialization / import workflows
}
After such operations, downstream analysis functions (e.g.,
\code{\link{pedstats}}, \code{\link{pedne}}) will either error or
automatically restore the class. You can also call \code{as_tidyped()}
explicitly to restore the class yourself.
}
\examples{
library(visPedigree)
tp <- tidyped(simple_ped)
class(tp)
# [1] "tidyped"    "data.table" "data.frame"

# Simulate class loss via rbind()
tp2 <- rbind(tp[1:5], tp[6:10])
class(tp2)
# [1] "data.table" "data.frame"

# Restore the class
tp3 <- as_tidyped(tp2)
class(tp3)
# [1] "tidyped"    "data.table" "data.frame"

# It can also restore from a plain data.frame if core columns are intact
tp_df <- as.data.frame(tp)
tp4 <- tp_df[tp_df$Gen > 1, ]
class(tp4)
# [1] "data.frame"

tp5 <- as_tidyped(tp4)
class(tp5)
# [1] "tidyped"    "data.table" "data.frame"

}
\seealso{
\code{\link{tidyped}}, \code{\link{new_tidyped}}
}
