2525# '
2626# ' nested_dm$airlines
2727dm_nest_tbl <- function (dm , child_table , into = NULL ) {
28+ dm_local_error_call()
29+
2830 # process args
2931 into <- enquo(into )
3032 # FIXME: Rename table_name to child_tables_name
@@ -52,27 +54,24 @@ dm_nest_tbl <- function(dm, child_table, into = NULL) {
5254
5355 # make sure we have a terminal child
5456 if (length(children ) || ! length(parent_name ) || length(parent_name ) > 1 ) {
55- if (length(parent_name )) {
56- parent_msg <- paste0(" \n parents: " , toString(paste0(" `" , parent_name , " `" )))
57- } else {
58- parent_msg <- " "
59- }
60- if (length(children )) {
61- children_msg <- paste0(" \n children: " , toString(paste0(" `" , children , " `" )))
62- } else {
63- children_msg <- " "
64- }
65- abort(glue(
66- " `{table_name}` can't be nested because it is not a terminal child table." ,
67- " {parent_msg}{children_msg}"
68- ))
57+ cli :: cli_abort(
58+ c(
59+ " {.val {table_name}} can't be nested because it is not a terminal child table." ,
60+ if (length(parent_name )) " parents: {.val {parent_name}}" ,
61+ if (length(children )) " children: {.val {children}}"
62+ ),
63+ call = dm_error_call()
64+ )
6965 }
7066
7167 # check consistency of `into` if relevant
7268 if (! quo_is_null(into )) {
7369 into <- dm_tbl_name(dm , !! into )
7470 if (into != parent_name ) {
75- abort(glue(" `{table_name}` can only be packed into `{child_name}`" ))
71+ cli :: cli_abort(
72+ " {.val {table_name}} can only be packed into {.val {child_name}}." ,
73+ call = dm_error_call()
74+ )
7675 }
7776 }
7877
@@ -126,6 +125,8 @@ dm_nest_tbl <- function(dm, child_table, into = NULL) {
126125# '
127126# ' dm_packed$flights$planes
128127dm_pack_tbl <- function (dm , parent_table , into = NULL ) {
128+ dm_local_error_call()
129+
129130 # process args
130131 into <- enquo(into )
131132 table_name <- dm_tbl_name(dm , {{ parent_table }})
@@ -147,7 +148,10 @@ dm_pack_tbl <- function(dm, parent_table, into = NULL) {
147148 if (! quo_is_null(into )) {
148149 into <- dm_tbl_name(dm , !! into )
149150 if (into != child_name ) {
150- abort(glue(" `{table_name}` can only be packed into `{child_name}`" ))
151+ cli :: cli_abort(
152+ " {.val {table_name}} can only be packed into {.val {child_name}}." ,
153+ call = dm_error_call()
154+ )
151155 }
152156 }
153157
@@ -181,21 +185,14 @@ check_table_can_be_packed <- function(table_name, children_names, fks) {
181185 table_has_one_child <- length(children_names ) == 1
182186 table_is_terminal_parent <- table_has_one_child && ! table_has_parents
183187 if (! table_is_terminal_parent ) {
184- if (table_has_parents ) {
185- parent_msg <- paste0(" \n parents : " , toString(paste0(" `" , parents , " `" )))
186- } else {
187- parent_msg <- " "
188- }
189- table_has_children <- length(children_names ) > 0
190- if (table_has_children ) {
191- children_msg <- paste0(" \n children: " , toString(paste0(" `" , children_names , " `" )))
192- } else {
193- children_msg <- " "
194- }
195- abort(glue(
196- " `{table_name}` can't be packed because it is not a terminal parent table." ,
197- " {parent_msg}{children_msg}"
198- ))
188+ cli :: cli_abort(
189+ c(
190+ " {.val {table_name}} can't be packed because it is not a terminal parent table." ,
191+ if (length(parents ) > 0 ) " parents : {.val {parents}}" ,
192+ if (length(children_names ) > 0 ) " children: {.val {children_names}}"
193+ ),
194+ call = dm_error_call()
195+ )
199196 }
200197 invisible (NULL )
201198}
0 commit comments