papeR icon indicating copy to clipboard operation
papeR copied to clipboard

set labels via named vector

Open bastistician opened this issue 6 years ago • 0 comments

Setting labels for a subset of the variables is supported by the argument which of the labels<- function. So we can do:

data(Orthodont, package = "nlme")
labels(Orthodont, which = "distance") <- "Fissure distance (mm)"

I suggest to allow for an alternative syntax for setting labels via a named vector, consistent with how labels() are extracted.

labels(Orthodont) <- c("distance" = "Fissure distance (mm)")

I would much prefer that syntax, especially for labelling a lot of variables simultanously, because the variable names and labels are more closely connected.

This alternative syntax is probably straightforward to implement given the current implementation: https://github.com/hofnerb/papeR/blob/9e79d5b1c73e8a2db69449b19104bc65926b776d/R/labels.R#L59-L61 Maybe add the following at the beginning of the function body:

if (!is.null(names(value)) {
    if (!is.null(which))
        warning("ignoring argument 'which' since labels are named")
    which <- names(value)
}

bastistician avatar Feb 06 '19 08:02 bastistician