Fix bug, add tests and update NEWS - #294
Conversation
Code Coverage SummaryDiff against mainResults for commit: 5db9b00 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Unit Tests Summary 1 files 14 suites 7s ⏱️ Results for commit 5db9b00. ♻️ This comment has been updated with latest results. |
Unit Test Performance DifferenceAdditional test case details
Results for commit c6b7730 ♻️ This comment has been updated with latest results. |
averissimo
left a comment
There was a problem hiding this comment.
This block is not very good, it works, but barely. It doesn't make sense to replace first instance after assignment, it would make sense to replace first instance in parenthesis.
See example below that incorrectly replaces first occurrence (the one not in parenthesis)
browser() statement was placed just before returned modified result
pkgload::load_all(".")
data <- qenv()
data <- within(data, {
mtcars <- datasets::mtcars
#mtcars <- mtcars[mtcars$cyl == 4, ]
aa <- seq_len(nrow(mtcars))
mtcars <- mtcars$mpg > 15 & aa[mtcars$mpg & mtcars$cyl]
# mtcars <- mtcars[mtcars$cyl == 4, ]
})
get_code(data, names = "mtcars") |> cat()Could we simplify the code to just return c(ans, in_parenthesis(pd))
We don't really care about having repeated element, or do we?
diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R
index 1bd38ef0..5b2ac04d 100644
--- a/R/utils-get_code_dependency.R
+++ b/R/utils-get_code_dependency.R
@@ -304,24 +304,7 @@ extract_occurrence <- function(pd) {
after <- match(min(x$id[assign_cond]), sort(x$id[c(min(assign_cond), sym_cond)])) - 1
ans <- append(x[sym_cond, "text"], "<-", after = max(1, after))
ans <- move_functions_after_arrow(ans, unique(x[sym_fc_cond, "text"]))
- roll <- in_parenthesis(pd)
- if (length(roll)) {
- # detect elements appeared in parenthesis and move them on RHS
- # but only their first appearance after assignment
- # as the same object can appear as regular object and the one used in parenthesis
- result <- ans
- arrow_idx <- which(result == "<-")
- for (elem in roll) {
- idx <- which(result == elem)
- idx <- idx[idx > arrow_idx][1]
- if (!is.na(idx)) {
- result <- result[-idx]
- }
- }
- c(result, roll)
- } else {
- ans
- }
+ c(ans, in_parenthesis(pd))
}
#' Moves function names to the right side of dependency graph
|
Great simplification! I think we do care about the position of the elements and using |
Pull Request
Fixes #293
This is a minimal patch (mostly generated with AI) that fixes the test cases by skipping objects that are on the LHS.
This has revealed several issues that I'm considering what to do with it:
extract_dependency()list objects not present (cyl column on the first test added).extract_dependency()