R/dataReporter_as_factor.R

Defines functions dataReporter_haven_replace_with_old dataReporter_as_factor

#'@importFrom haven as_factor
dataReporter_as_factor <- function(v) {
  as_factor(v)
}



## Adding a verbatim copy of the unexported function dataReporter_haven_replace_with
## so a note does not pop up when checking the package.
dataReporter_haven_replace_with_old <- function(x, from, to) 
{
    stopifnot(length(from) == length(to))
    #out <- x
    out <- rep(NA, length(x))
    matches <- match(x, from, incomparables = NA)

    if (anyNA(matches)) {
      out[!is.na(matches)] <- to[matches[!is.na(matches)]]
    } else {
      out <- to[matches]
    }

    tagged <- haven::is_tagged_na(x)
    if (!any(tagged)) {
        return(out)
    }
    matches <- match(haven::na_tag(x), haven::na_tag(from), incomparables = NA)
    out[!is.na(matches)] <- to[matches[!is.na(matches)]]
    out
}

Try the dataReporter package in your browser

Any scripts or data that you put into this service are public.

dataReporter documentation built on Nov. 11, 2021, 9:06 a.m.