Skip to content

Commit efbdff5

Browse files
[skip style] [skip vbump] Restyle files
1 parent 3e5048e commit efbdff5

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

R/utils-get_code_dependency.R

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ extract_occurrence <- function(pd) {
216216
if (!is.null(data_dependency)) {
217217
return(data_dependency)
218218
}
219-
219+
220220
assign_dependency <- handle_assign_call(pd)
221221
if (!is.null(assign_dependency)) {
222222
return(assign_dependency)
223223
}
224-
224+
225225
# Process general assignment expressions
226226
extract_general_assignment(pd)
227227
}
@@ -239,7 +239,7 @@ handle_data_call <- function(pd) {
239239
if (data_call_pos == 0) {
240240
return(NULL)
241241
}
242-
242+
243243
# Extract the object name from data(object)
244244
object_name <- pd[data_call_pos + 1, "text"]
245245
# Remove quotes if present: data("object") -> object
@@ -260,12 +260,12 @@ handle_assign_call <- function(pd) {
260260
if (assign_call_pos == 0) {
261261
return(NULL)
262262
}
263-
263+
264264
param_position <- get_assign_param_position(pd)
265265
if (param_position == 0) {
266266
return(character(0L))
267267
}
268-
268+
269269
# Extract the assigned object name
270270
object_name <- pd[assign_call_pos + param_position, "text"]
271271
# Remove quotes if present: assign("object", value) -> object
@@ -285,14 +285,14 @@ handle_assign_call <- function(pd) {
285285
get_assign_param_position <- function(pd) {
286286
# Check if any parameters are named
287287
has_named_params <- any(pd$token == "SYMBOL_SUB")
288-
288+
289289
if (has_named_params) {
290290
# Extract parameter tokens: named parameters (SYMBOL_SUB), commas, equals
291291
param_tokens <- pd[pd$token %in% c("SYMBOL_SUB", "','", "EQ_SUB"), "text"]
292-
292+
293293
# Clean up sequences of "=" followed by ","
294294
cleaned_params <- remove_consecutive_equals_comma(param_tokens)
295-
295+
296296
# Find position of 'x' parameter among named parameters
297297
pos <- match("x", setdiff(cleaned_params, ","), nomatch = 0)
298298
if (pos == 0) {
@@ -316,14 +316,14 @@ remove_consecutive_equals_comma <- function(params) {
316316
if (length(params) <= 1) {
317317
return(params)
318318
}
319-
319+
320320
indices_to_remove <- integer(0)
321321
for (i in 2:length(params)) {
322322
if (params[i - 1] == "=" && params[i] == ",") {
323323
indices_to_remove <- c(indices_to_remove, i - 1, i)
324324
}
325325
}
326-
326+
327327
if (length(indices_to_remove) > 0) {
328328
params[-indices_to_remove]
329329
} else {
@@ -343,25 +343,25 @@ remove_consecutive_equals_comma <- function(params) {
343343
extract_general_assignment <- function(pd) {
344344
# Filter out symbols that are function parameters
345345
filtered_pd <- pd[!is_symbol_in_function_body(pd), ]
346-
346+
347347
# Find all symbol positions
348348
symbol_indices <- which(filtered_pd$token %in% c("SPECIAL", "SYMBOL", "SYMBOL_FUNCTION_CALL"))
349349
function_call_indices <- which(filtered_pd$token == "SYMBOL_FUNCTION_CALL")
350-
350+
351351
if (length(symbol_indices) == 0) {
352352
return(character(0L))
353353
}
354-
354+
355355
# Remove symbols that come after $ or @ operators (e.g., in x$a, remove 'a')
356356
symbol_indices <- exclude_symbols_after_operators(filtered_pd, symbol_indices)
357-
357+
358358
# Look for assignment operators
359359
assignment_indices <- grep("ASSIGN", filtered_pd$token)
360360
if (length(assignment_indices) == 0) {
361361
# No assignment found, return all symbols as dependencies
362362
return(c("<-", unique(filtered_pd[symbol_indices, "text"])))
363363
}
364-
364+
365365
# Process assignment expression
366366
process_assignment_expression(filtered_pd, symbol_indices, function_call_indices, assignment_indices, pd)
367367
}
@@ -377,7 +377,7 @@ is_symbol_in_function_body <- function(pd) {
377377
if (length(function_ids) == 0) {
378378
return(rep(FALSE, nrow(pd)))
379379
}
380-
380+
381381
# Get all children of function definitions
382382
function_children <- get_children(pd, function_ids[1])$id
383383
pd$id %in% function_children
@@ -396,11 +396,11 @@ exclude_symbols_after_operators <- function(pd, symbol_indices) {
396396
if (length(operator_ids) == 0) {
397397
return(symbol_indices)
398398
}
399-
399+
400400
# For x$a, a's ID is $'s ID-2, so we exclude symbols with ID = operator_ID - 2
401401
symbol_ids <- pd[symbol_indices, "id"]
402402
symbols_after_operators <- symbol_ids[(symbol_ids - 2) %in% operator_ids]
403-
403+
404404
# Remove these symbols from our indices
405405
setdiff(symbol_indices, which(pd$id %in% symbols_after_operators))
406406
}
@@ -409,7 +409,7 @@ exclude_symbols_after_operators <- function(pd, symbol_indices) {
409409
#'
410410
#' @param pd `data.frame` filtered parse data
411411
#' @param symbol_indices Integer vector of symbol positions
412-
#' @param function_call_indices Integer vector of function call positions
412+
#' @param function_call_indices Integer vector of function call positions
413413
#' @param assignment_indices Integer vector of assignment operator positions
414414
#' @param original_pd `data.frame` original parse data for bracket processing
415415
#' @return Character vector with dependency information
@@ -418,19 +418,19 @@ exclude_symbols_after_operators <- function(pd, symbol_indices) {
418418
process_assignment_expression <- function(pd, symbol_indices, function_call_indices, assignment_indices, original_pd) {
419419
# Remove function calls that appear before assignment (e.g., in eval(expression(c <- b)))
420420
symbol_indices <- symbol_indices[!(symbol_indices < min(assignment_indices) & symbol_indices %in% function_call_indices)]
421-
421+
422422
# Handle right-to-left assignment (->) by reversing symbol order
423423
if (unique(pd$text[assignment_indices]) == "->") {
424424
symbol_indices <- rev(symbol_indices)
425425
}
426-
426+
427427
# Build dependency vector with assignment operator in correct position
428428
assignment_pos <- match(min(pd$id[assignment_indices]), sort(pd$id[c(min(assignment_indices), symbol_indices)])) - 1
429429
dependency_vector <- append(pd[symbol_indices, "text"], "<-", after = max(1, assignment_pos))
430-
430+
431431
# Move function names to right side of dependency arrow
432432
dependency_vector <- move_functions_after_arrow(dependency_vector, unique(pd[function_call_indices, "text"]))
433-
433+
434434
# Handle symbols in brackets/parentheses
435435
bracket_symbols <- extract_symbols_in_brackets(original_pd)
436436
if (length(bracket_symbols) > 0) {
@@ -452,10 +452,10 @@ extract_symbols_in_brackets <- function(pd) {
452452
if (!has_brackets) {
453453
return(NULL)
454454
}
455-
455+
456456
start_id <- min(pd$id[pd$token %in% c("LBB", "'['")])
457457
end_id <- min(pd$id[pd$token == "']'"])
458-
458+
459459
# Extract symbols between brackets
460460
pd$text[pd$token == "SYMBOL" & pd$id > start_id & pd$id < end_id]
461461
}

0 commit comments

Comments
 (0)