@@ -66,16 +66,60 @@ check_constraints.qf_table <- function(x) {
6666
6767# ' @noRd
6868# ' @exportS3Method utils::str
69- str.qf_table <- function (object , ... ) {
70- cat(" <qf_table> [" , nrow(object ), " x " , ncol(object ), " ]\n " , sep = " " )
71- cat(" Columns: " , paste(colnames(object ), collapse = " , " ), " \n " , sep = " " )
72- cat(
73- " Constraints: " ,
74- paste(purrr :: map(constraints(object ),
75- \(cstr ) paste(" <" , class(cstr )[[1 ]], " >" , sep = " " )
76- ), collapse = " , " ),
77- " \n " , sep = " "
69+ str.qf_table <- function (object ,
70+ show.context = TRUE ,
71+ nest.lev = 0 ,
72+ indent.str = paste(rep.int(" " , max(0 , nest.lev + 1 )), collapse = " .." ),
73+ ...
74+ ) {
75+ dots <- list (... )
76+ context <- attr(object , " context" )
77+ attr(object , " context" ) <- NULL
78+
79+ # Header
80+ cat(" <qf_table>\n " )
81+
82+ # Columns / data
83+ cat(indent.str , " - Data:" , sep = " " )
84+ NextMethod(
85+ nest.lev = nest.lev + 1 ,
86+ indent.str = paste(rep.int(" " , max(0 , nest.lev + 2 )),
87+ collapse = " .." ),
88+ give.attr = FALSE
7889 )
90+
91+ # Constraints
92+ cat(indent.str , " - Constraints:" , " \n " , sep = " " )
93+ constraint_types <- constraints(object ) | >
94+ vapply(pretty_class , character (1 )) | >
95+ format()
96+ constraint_cols <- constraints(object ) | >
97+ vapply(\(cstr ) {
98+ col_names <- paste0(" [" , paste(cstr $ cols , collapse = " , " ), " ]" )
99+ if (inherits(cstr , " cstr_foreign_key" )) {
100+ ref_col_names <- paste(cstr $ ref_cols , collapse = " , " )
101+ paste0(col_names , " => " , cstr $ ref_table , " [" , ref_col_names , " ]" )
102+ } else {
103+ col_names
104+ }
105+ }, character (1 ))
106+ paste0(indent.str , " .." , " - " , constraint_types , " " , constraint_cols ) | >
107+ cat(sep = " \n " )
108+
109+ # Context
110+ if (show.context && ! is.null(context )) {
111+ cat(indent.str , " - Context: " , pretty_class(context ), " : " , sep = " " )
112+ cat(names(context ), sep = " , " )
113+ cat(" \n " )
114+ }
115+
116+ invisible (object )
117+ }
118+
119+ # ' @noRd
120+ # ' @export
121+ print.qf_table <- function (x , ... ) {
122+ str(x )
79123}
80124
81125
0 commit comments