Skip to content

Commit cfa3d02

Browse files
committed
improve documentation of meta()
1 parent 832914b commit cfa3d02

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

R/meta.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#' Optimize an Object for Storage as Plain Text and Add Metadata
22
#'
3-
#' \code{\link{write_vc}} applies this function automatically on your
4-
#' data.frame to optimize the data.frame and generate the metadata.
3+
#' @description
4+
#' Prepares a vector for storage. When relevant, `meta()`optimizes the object
5+
#' for storage by changing the format to one which needs less characters. The
6+
#' metadata stored in the `meta` attribute, contains all required information to
7+
#' backtransform the optimized format into the original format.
58
#' @param x the vector.
69
#' @param ... further arguments to the methods.
710
#' @return the optimized vector `x` with `meta` attribute.
@@ -174,8 +177,15 @@ meta.Date <- function(x, optimize = TRUE, ...){
174177
#' @export
175178
#' @importFrom assertthat assert_that
176179
#' @importFrom utils packageVersion
177-
#' @note `..generic` is a reserved name for the metadata and therefore not
178-
#' allowed column name in a `data.frame`.
180+
#' @description
181+
#' In case of a data.frame, `meta()` applies itself to each of the columns. The
182+
#' `meta` attribute becomes a named list containing the metadata for each column
183+
#' plus an additional `..generic` element. `..generic` is a reserved name for
184+
#' the metadata and not allowed as column name in a `data.frame`.
185+
#'
186+
#' \code{\link{write_vc}} uses this function to prepare a dataframe for storage.
187+
#' Existing metadata is passed through the optional `old` argument. This
188+
#' argument intendent for internal use.
179189
#' @rdname meta
180190
#' @inheritParams write_vc
181191
meta.data.frame <- function(x, optimize = TRUE, na = "NA", sorting, ...) {
@@ -203,7 +213,7 @@ Sorting is strongly recommended in combination with version control.")
203213
all(sorting %in% colnames(x)),
204214
msg = "All sorting variables must be available in the data.frame")
205215
if (nrow(x) > 1) {
206-
x <- x[do.call(order, x[sorting]), , drop = FALSE] # nolint
216+
x <- x[do.call(order, unname(x[sorting])), , drop = FALSE] # nolint
207217
if (any_duplicated(x[sorting])) {
208218
sorted <- paste(sprintf("'%s'", sorting), collapse = ", ")
209219
sorted <- sprintf("Sorting on %s results in ties.

man/meta.Rd

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)