Skip to content

Commit 0ebd5b7

Browse files
committed
chore: Auto-update from GitHub Actions
Run: https://github.com/cynkra/dm/actions/runs/22226432787
1 parent ce923a9 commit 0ebd5b7

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

R/paste.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ dm_paste_impl <- function(dm, options, tab_width) {
127127
code_fks,
128128
code_color
129129
)
130-
130+
131131
# remove any NULL/empty elements
132132
all_operations <- all_operations[lengths(all_operations) > 0]
133-
133+
134134
# combine dm and paste code with chunking if needed
135135
code_dm <- dm_paste_chunk_operations(
136136
code_construct,
@@ -257,13 +257,13 @@ dm_paste_chunk_operations <- function(code_construct, all_operations, tab, chunk
257257
sep = glue(" %>%\n{tab}", .trim = FALSE)
258258
))
259259
}
260-
260+
261261
# Split operations into chunks
262262
chunks <- split(all_operations, ceiling(seq_along(all_operations) / chunk_size))
263-
263+
264264
# Generate code for each chunk
265265
chunk_codes <- vector("character", length(chunks))
266-
266+
267267
for (i in seq_along(chunks)) {
268268
if (i == 1) {
269269
# First chunk includes the dm construction
@@ -279,23 +279,23 @@ dm_paste_chunk_operations <- function(code_construct, all_operations, tab, chunk
279279
)
280280
}
281281
}
282-
282+
283283
# If only one chunk, return it directly
284284
if (length(chunks) == 1) {
285285
return(chunk_codes[1])
286286
}
287-
287+
288288
# Generate intermediate variable assignments and final result
289289
result_lines <- character()
290-
290+
291291
for (i in seq_along(chunk_codes)) {
292292
var_name <- if (i == length(chunk_codes)) {
293293
# Last chunk - no assignment, just the expression
294294
NULL
295295
} else {
296296
paste0("dm_step_", i)
297297
}
298-
298+
299299
if (i == 1) {
300300
# First chunk
301301
if (!is.null(var_name)) {
@@ -307,15 +307,15 @@ dm_paste_chunk_operations <- function(code_construct, all_operations, tab, chunk
307307
# Subsequent chunks
308308
prev_var_name <- paste0("dm_step_", i - 1)
309309
chunk_with_var <- paste0(prev_var_name, " %>%\n", tab, chunk_codes[i])
310-
310+
311311
if (!is.null(var_name)) {
312312
result_lines <- c(result_lines, paste0(var_name, " <- ", chunk_with_var))
313313
} else {
314314
result_lines <- c(result_lines, chunk_with_var)
315315
}
316316
}
317317
}
318-
318+
319319
paste(result_lines, collapse = "\n\n")
320320
}
321321

tests/testthat/test-paste.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ test_that("output 2", {
108108

109109
test_that("chunking behavior for large dm", {
110110
# Test that dm_paste chunks long pipe chains to avoid stack overflow
111-
111+
112112
# Create a dm with many tables and foreign keys to trigger chunking
113113
create_large_dm <- function(n_tables = 55) {
114114
# Create main table
115115
main_table <- tibble(id = integer(0))
116-
116+
117117
# Create list of tables
118118
tables <- list(main = main_table)
119-
119+
120120
# Create many tables that reference the main table
121121
for (i in 1:n_tables) {
122122
table_name <- paste0("table_", i)
@@ -125,46 +125,46 @@ test_that("chunking behavior for large dm", {
125125
main_id = integer(0)
126126
)
127127
}
128-
128+
129129
# Create dm
130130
dm_obj <- do.call(dm, tables)
131-
131+
132132
# Add primary key to main table
133133
dm_obj <- dm_obj %>% dm_add_pk(main, id)
134-
134+
135135
# Add primary keys and foreign keys to all other tables
136136
for (i in 1:n_tables) {
137137
table_name <- paste0("table_", i)
138-
dm_obj <- dm_obj %>%
138+
dm_obj <- dm_obj %>%
139139
dm_add_pk(!!table_name, id) %>%
140140
dm_add_fk(!!table_name, main_id, main)
141141
}
142-
142+
143143
return(dm_obj)
144144
}
145-
145+
146146
# Create a dm with 55 tables (should generate ~165 operations: 56 PKs + 55 FKs + 54 color ops)
147147
large_dm <- create_large_dm(55)
148-
148+
149149
# Capture output
150150
output <- capture.output(dm_paste(large_dm))
151151
output_text <- paste(output, collapse = "\n")
152-
152+
153153
# Should generate more than 100 operations, triggering chunking
154154
# Check for intermediate variable assignments
155155
expect_true(
156156
grepl("dm_step_", output_text),
157157
info = "Expected chunking with intermediate variables for large dm"
158158
)
159-
159+
160160
# Check that we have at least one intermediate step
161161
step_count <- length(gregexpr("dm_step_", output_text)[[1]])
162162
expect_gt(
163-
step_count,
163+
step_count,
164164
0,
165165
info = "Expected at least one intermediate step variable"
166166
)
167-
167+
168168
# Verify the final output references an intermediate variable
169169
expect_true(
170170
grepl("dm_step_\\d+ %>%", output_text),

0 commit comments

Comments
 (0)