Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set labels via named vector #42

Open
bastistician opened this issue Feb 6, 2019 · 0 comments
Open

set labels via named vector #42

bastistician opened this issue Feb 6, 2019 · 0 comments

Comments

@bastistician
Copy link

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:

papeR/R/labels.R

Lines 59 to 61 in 9e79d5b

"labels<-" <- function(data, which = NULL, value){
which <- check_which(which, data, "define")

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant