Skip to content

Commit

Permalink
it's possible to create a character labelled variable with haven
Browse files Browse the repository at this point in the history
  • Loading branch information
larmarange committed Jul 5, 2015
1 parent 15d1e7f commit 4109beb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/labels.r
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ sji.getValueLabel <- function(x, include.values = NULL) {
# check if we have anything
if (!is.null(lab)) {
# retrieve values associated with labels
values <- as.numeric(unname(attr(x, attr.string, exact = T)))
if (is.character(x))
values <- unname(attr(x, attr.string, exact = T))
else
values <- as.numeric(unname(attr(x, attr.string, exact = T)))
# retrieve order of value labels
reihenfolge <- order(values)
# retrieve label values in correct order
Expand All @@ -81,7 +84,10 @@ sji.getValueLabel <- function(x, include.values = NULL) {
}
# here we include values as prefix of labels
if (include.values == "as.prefix" || include.values == "p") {
labels <- sprintf("[%i] %s", values[reihenfolge], labels)
if (is.numeric(x))
labels <- sprintf("[%i] %s", values[reihenfolge], labels)
else
labels <- sprintf("[%s] %s", values[reihenfolge], labels)
}
}
}
Expand Down

0 comments on commit 4109beb

Please sign in to comment.