-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.contents.R
47 lines (40 loc) · 1.29 KB
/
print.contents.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#' @title Print a contents object
#' @description
#' \code{print.contents} prints the results of the content function.
#' @param x a object of class \code{contents}
#' @param ... not used.
#' @return NULL
#'
#' @examples
#' testdata <- data.frame(height=c(4, 5, 3, 2, 100),
#' weight=c(39, 88, NA, 15, -2),
#' names=c("Bill","Dean", "Sam", NA, "Jane"),
#' race=c('b', 'w', 'w', 'o', 'b'))
#'
#' x <- contents(testdata)
#' print(x)
#'
#' @rdname print.contents
#' @importFrom crayon blue
#' @export
print.contents <- function(x, ...){
if(!inherits(x, "contents")) stop("Must be class 'tab'")
cat("\nThe data frame", x$dfname, "has",
format(x$nrow, big.mark=","), "observations and",
format(x$ncol, big.mark=","), "variables.\n")
if(x$nrow == 0 | x$ncol == 0)return(NULL)
cat("\n", crayon::blue$underline$bold('Overall'), "\n", sep="")
print(x$overall, row.names=FALSE, right=FALSE)
if(!is.null(x$qvars)){
cat("\n", crayon::blue$underline$bold('Numeric Variables'),
"\n", sep="")
print(x$qvars)
}
if(!is.null(x$cvars)){
cat("\n",
crayon::blue$underline$bold('Categorical Variables'),
"\n", sep="")
print.data.frame(x$cvars, right=FALSE, row.names=FALSE)
}
return(NULL)
}