mirror of
https://github.com/agdamsbo/FreesearchR.git
synced 2026-06-19 04:27:30 +02:00
fix: keeps labels modifying factors and creates new factors correctly
This commit is contained in:
parent
fe1609b4f6
commit
32f299880d
23 changed files with 676 additions and 80 deletions
21
man/apply_labels.Rd
Normal file
21
man/apply_labels.Rd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/utils-labels.R
|
||||
\name{apply_labels}
|
||||
\alias{apply_labels}
|
||||
\title{Apply a named label vector to a data frame}
|
||||
\usage{
|
||||
apply_labels(df, labels)
|
||||
}
|
||||
\arguments{
|
||||
\item{df}{A data frame.}
|
||||
|
||||
\item{labels}{A named character vector (names = column names, values = labels).
|
||||
Typically the output of \code{\link[=extract_labels]{extract_labels()}}. Labels for absent columns are
|
||||
silently ignored.}
|
||||
}
|
||||
\value{
|
||||
\code{df} with \code{"label"} attributes set on matching columns.
|
||||
}
|
||||
\description{
|
||||
Apply a named label vector to a data frame
|
||||
}
|
||||
17
man/extract_labels.Rd
Normal file
17
man/extract_labels.Rd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/utils-labels.R
|
||||
\name{extract_labels}
|
||||
\alias{extract_labels}
|
||||
\title{Extract column labels from a data frame}
|
||||
\usage{
|
||||
extract_labels(df)
|
||||
}
|
||||
\arguments{
|
||||
\item{df}{A data frame.}
|
||||
}
|
||||
\value{
|
||||
A named character vector of label strings (only labelled columns included).
|
||||
}
|
||||
\description{
|
||||
Extract column labels from a data frame
|
||||
}
|
||||
19
man/label_report.Rd
Normal file
19
man/label_report.Rd
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/utils-labels.R
|
||||
\name{label_report}
|
||||
\alias{label_report}
|
||||
\title{Print a tidy summary of column labels}
|
||||
\usage{
|
||||
label_report(df, missing_marker = "(no label)")
|
||||
}
|
||||
\arguments{
|
||||
\item{df}{A data frame.}
|
||||
|
||||
\item{missing_marker}{String used when a column has no label. Default: \code{"(no label)"}.}
|
||||
}
|
||||
\value{
|
||||
A \code{column / class / label} data frame, printed and returned invisibly.
|
||||
}
|
||||
\description{
|
||||
Print a tidy summary of column labels
|
||||
}
|
||||
20
man/restore_labels.Rd
Normal file
20
man/restore_labels.Rd
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/utils-labels.R
|
||||
\name{restore_labels}
|
||||
\alias{restore_labels}
|
||||
\title{Restore column labels using a reference data frame}
|
||||
\usage{
|
||||
restore_labels(df_modified, df_reference)
|
||||
}
|
||||
\arguments{
|
||||
\item{df_modified}{A data frame whose columns should receive labels.}
|
||||
|
||||
\item{df_reference}{A data frame carrying the authoritative \code{"label"} attributes.}
|
||||
}
|
||||
\value{
|
||||
\code{df_modified} with labels restored on all columns present in \code{df_reference}.
|
||||
}
|
||||
\description{
|
||||
Convenience wrapper around \code{\link[=extract_labels]{extract_labels()}} + \code{\link[=apply_labels]{apply_labels()}}. Labels are
|
||||
matched by column name; new columns in \code{df_modified} are left unchanged.
|
||||
}
|
||||
21
man/with_labels.Rd
Normal file
21
man/with_labels.Rd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/utils-labels.R
|
||||
\name{with_labels}
|
||||
\alias{with_labels}
|
||||
\title{Evaluate an expression while preserving column labels}
|
||||
\usage{
|
||||
with_labels(df, expr)
|
||||
}
|
||||
\arguments{
|
||||
\item{df}{A data frame carrying \code{"label"} attributes.}
|
||||
|
||||
\item{expr}{An unquoted expression that transforms \code{df} and returns a data frame.}
|
||||
}
|
||||
\value{
|
||||
The data frame produced by \code{expr}, with original labels restored.
|
||||
}
|
||||
\description{
|
||||
Snapshots labels from \code{df} before evaluating \code{expr}, then reapplies them to
|
||||
matching columns in the result. New columns created inside \code{expr} receive no
|
||||
label automatically.
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue