|
1 | 1 | #' Optimize an Object for Storage as Plain Text and Add Metadata |
2 | 2 | #' |
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. |
5 | 8 | #' @param x the vector. |
6 | 9 | #' @param ... further arguments to the methods. |
7 | 10 | #' @return the optimized vector `x` with `meta` attribute. |
@@ -174,8 +177,15 @@ meta.Date <- function(x, optimize = TRUE, ...){ |
174 | 177 | #' @export |
175 | 178 | #' @importFrom assertthat assert_that |
176 | 179 | #' @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. |
179 | 189 | #' @rdname meta |
180 | 190 | #' @inheritParams write_vc |
181 | 191 | meta.data.frame <- function(x, optimize = TRUE, na = "NA", sorting, ...) { |
@@ -203,7 +213,7 @@ Sorting is strongly recommended in combination with version control.") |
203 | 213 | all(sorting %in% colnames(x)), |
204 | 214 | msg = "All sorting variables must be available in the data.frame") |
205 | 215 | 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 |
207 | 217 | if (any_duplicated(x[sorting])) { |
208 | 218 | sorted <- paste(sprintf("'%s'", sorting), collapse = ", ") |
209 | 219 | sorted <- sprintf("Sorting on %s results in ties. |
|
0 commit comments