R/frequencies.R

Defines functions pander.frequencies print.frequencies frequencies

Documented in frequencies pander.frequencies print.frequencies

frequencies <- function(..., digits = 1, nsmall=1, transposed=FALSE, round=1,
                    plot=FALSE, plotTheme = theme_bw()) {

  ### Call functions to explore the variables
  res <- lapply(list(...), function(x) {
    rsl <- list();
    rsl$freq <- freq(x, digits=digits, nsmall=nsmall,
                     transposed=transposed, round=round,
                     plot=plot, plotTheme=plotTheme);
    return(rsl);
  });

  ### Get the variable names
  names(res) <- unlist(as.list(substitute(list(...)))[-1]);

  ### Set class for correct printing and return result
  class(res) <- 'frequencies';
  return(res);
}

print.frequencies <- function(x, ...) {
  for (currentName in names(x)) {
    cat0("### Frequencies for '", extractVarName(currentName), "'\n\n");
    print(x[[currentName]]$freq);
    cat("\n");
  }
}

pander.frequencies <- function(x, prefix="###", ...) {
  for (currentName in names(x)) {
    cat0(prefix, " Frequencies for '", extractVarName(currentName), "'\n\n");
    pander(x[[currentName]]$freq);
    cat("\n");
  }
}

Try the userfriendlyscience package in your browser

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

userfriendlyscience documentation built on Nov. 18, 2017, 4:14 a.m.