From bf9dcd05176bbe714d0ddd0e22389f0dca1473db Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 5 Aug 2025 14:42:55 +0200 Subject: [PATCH 01/17] fix #262 --- R/utils-get_code_dependency.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index 8596ae420..8e23f9374 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -303,6 +303,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)) { c(setdiff(ans, roll), roll) @@ -311,6 +312,16 @@ extract_occurrence <- function(pd) { } } +move_functions_after_arrow <- function(ans, functions) { + arrow_pos <- which(ans == "<-") + if (length(arrow_pos) == 0) { + return(ans) + } + before_arrow <- setdiff(ans[1:arrow_pos], functions) + after_arrow <- ans[(arrow_pos + 1):length(ans)] + c(before_arrow, unique(c(intersect(ans[1:arrow_pos], functions), after_arrow))) +} + #' Extract side effects #' #' Extracts all object names from the code that are marked with `@linksto` tag. From 101231904e98f4a89aab58584fc093aa6e22217c Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 6 Aug 2025 14:21:31 +0200 Subject: [PATCH 02/17] documentation for move_functions_after_arrow --- R/utils-get_code_dependency.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index 8e23f9374..860a8bebf 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -312,6 +312,21 @@ extract_occurrence <- function(pd) { } } +#' Moves function names to the right side of dependency graph +#' +#' Move function names after the dependencya oprator (arrow) to the right side of the dependency graph. +#' Convenience utility needed to correctly detect dependencies between objects. +#' For cases when a function call is on the left side of the assignment operator, +#' it is moved to the right side of the arrow. +#' For example, for `attributes(a) <- b` the dependey graph should look like `c()"a", "<-", "b", "attributes")`. +#' +#' @param ans `character` vector of object names in dependency graph. +#' @param functions `character` vector of function names. +#' +#' @return +#' A character vector. +#' @keywords internal +#' @noRd move_functions_after_arrow <- function(ans, functions) { arrow_pos <- which(ans == "<-") if (length(arrow_pos) == 0) { From 54931eb9915287d59ab0f4f95ff80f95f5d497c1 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 6 Aug 2025 14:31:15 +0200 Subject: [PATCH 03/17] test for cyclic dependency --- tests/testthat/test-qenv_get_code.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index a5dc2975f..a846589cb 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -290,6 +290,18 @@ testthat::describe("get_code for specific names", { ) } ) + testthat::it("prevents cyclic dependencies when function (c) is on left side of assignment and right side of the oprations", { + code <- c( + "object_list <- list(x = iris, y = iris)", + "object_list_2 <- list(x = mtcars, y = mtcars)", + "object_list_2[c('x')] <- c('string')", + "object_list[c('x')] <- c('string')" + ) + q <- eval_code(qenv(), code = code) + result <- get_code(q, names = "object_list") + testthat::expect_identical(result, paste(code[c(1, 4)], collapse = "\n")) + }) + }) From 650db16c9ac92c63f86bbf8ad9284933894dc8ba Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 12:33:44 +0000 Subject: [PATCH 04/17] [skip style] [skip vbump] Restyle files --- tests/testthat/test-qenv_get_code.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index a846589cb..00bf62e77 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -301,7 +301,6 @@ testthat::describe("get_code for specific names", { result <- get_code(q, names = "object_list") testthat::expect_identical(result, paste(code[c(1, 4)], collapse = "\n")) }) - }) From 5cf4a86503cb21d1ffde1df45709ea97a5e21d81 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:39:05 +0200 Subject: [PATCH 05/17] Update tests/testthat/test-qenv_get_code.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dawid Kałędkowski Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- tests/testthat/test-qenv_get_code.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index 00bf62e77..51624d9d7 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -290,7 +290,7 @@ testthat::describe("get_code for specific names", { ) } ) - testthat::it("prevents cyclic dependencies when function (c) is on left side of assignment and right side of the oprations", { + testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", { code <- c( "object_list <- list(x = iris, y = iris)", "object_list_2 <- list(x = mtcars, y = mtcars)", From 3f408c5008059462546a80619f2d44c2b5e81a09 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:39:19 +0200 Subject: [PATCH 06/17] Update R/utils-get_code_dependency.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dawid Kałędkowski Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/utils-get_code_dependency.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index 860a8bebf..67dc4e282 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -315,7 +315,6 @@ extract_occurrence <- function(pd) { #' Moves function names to the right side of dependency graph #' #' Move function names after the dependencya oprator (arrow) to the right side of the dependency graph. -#' Convenience utility needed to correctly detect dependencies between objects. #' For cases when a function call is on the left side of the assignment operator, #' it is moved to the right side of the arrow. #' For example, for `attributes(a) <- b` the dependey graph should look like `c()"a", "<-", "b", "attributes")`. From 758917c4006de0cfc7e322ead327450f63e2722d Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:39:32 +0200 Subject: [PATCH 07/17] Update R/utils-get_code_dependency.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dawid Kałędkowski Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/utils-get_code_dependency.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index 67dc4e282..5bc4a5264 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -317,7 +317,7 @@ extract_occurrence <- function(pd) { #' Move function names after the dependencya oprator (arrow) to the right side of the dependency graph. #' For cases when a function call is on the left side of the assignment operator, #' it is moved to the right side of the arrow. -#' For example, for `attributes(a) <- b` the dependey graph should look like `c()"a", "<-", "b", "attributes")`. +#' For example, for `attributes(a) <- b` the dependency graph should look like `c("a", "<-", "b", "attributes")`. #' #' @param ans `character` vector of object names in dependency graph. #' @param functions `character` vector of function names. From 3c0c3609d996c2e8376f0556ebf9918d395e25f4 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:39:54 +0200 Subject: [PATCH 08/17] Update R/utils-get_code_dependency.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dawid Kałędkowski Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/utils-get_code_dependency.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index 5bc4a5264..c2747fcc1 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -314,7 +314,8 @@ extract_occurrence <- function(pd) { #' Moves function names to the right side of dependency graph #' -#' Move function names after the dependencya oprator (arrow) to the right side of the dependency graph. +#' Changes status of the function call from dependent to dependency if occurs in the lhs. +#' Technically, it means it to move function names after the dependency operator. #' For cases when a function call is on the left side of the assignment operator, #' it is moved to the right side of the arrow. #' For example, for `attributes(a) <- b` the dependency graph should look like `c("a", "<-", "b", "attributes")`. From 49d888d265f8ddd01c07b32784aa47e6fcda0fe0 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:40:07 +0200 Subject: [PATCH 09/17] Update R/utils-get_code_dependency.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dawid Kałędkowski Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/utils-get_code_dependency.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index c2747fcc1..2bf661889 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -316,8 +316,6 @@ extract_occurrence <- function(pd) { #' #' Changes status of the function call from dependent to dependency if occurs in the lhs. #' Technically, it means it to move function names after the dependency operator. -#' For cases when a function call is on the left side of the assignment operator, -#' it is moved to the right side of the arrow. #' For example, for `attributes(a) <- b` the dependency graph should look like `c("a", "<-", "b", "attributes")`. #' #' @param ans `character` vector of object names in dependency graph. From c29bb038754d3f5312cf7214fb5fe2d3d2f5ecc9 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 14:42:13 +0000 Subject: [PATCH 10/17] [skip style] [skip vbump] Restyle files --- R/utils-get_code_dependency.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index 2bf661889..ff82983cd 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -314,7 +314,7 @@ extract_occurrence <- function(pd) { #' Moves function names to the right side of dependency graph #' -#' Changes status of the function call from dependent to dependency if occurs in the lhs. +#' Changes status of the function call from dependent to dependency if occurs in the lhs. #' Technically, it means it to move function names after the dependency operator. #' For example, for `attributes(a) <- b` the dependency graph should look like `c("a", "<-", "b", "attributes")`. #' From c50f6868552f7e6655aa748366304ce5a399b20d Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Thu, 7 Aug 2025 10:57:03 +0200 Subject: [PATCH 11/17] Update R/utils-get_code_dependency.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dawid Kałędkowski Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/utils-get_code_dependency.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils-get_code_dependency.R b/R/utils-get_code_dependency.R index ff82983cd..42e0650ad 100644 --- a/R/utils-get_code_dependency.R +++ b/R/utils-get_code_dependency.R @@ -315,7 +315,7 @@ extract_occurrence <- function(pd) { #' Moves function names to the right side of dependency graph #' #' Changes status of the function call from dependent to dependency if occurs in the lhs. -#' Technically, it means it to move function names after the dependency operator. +#' Technically, it means to move function names after the dependency operator. #' For example, for `attributes(a) <- b` the dependency graph should look like `c("a", "<-", "b", "attributes")`. #' #' @param ans `character` vector of object names in dependency graph. From 06bb5514d4dde62169f9139d9b1ae603f785ac48 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 7 Aug 2025 11:01:17 +0200 Subject: [PATCH 12/17] superlintr --- tests/testthat/test-qenv_get_code.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index 51624d9d7..ba973813a 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -290,7 +290,8 @@ testthat::describe("get_code for specific names", { ) } ) - testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", { + testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", + { code <- c( "object_list <- list(x = iris, y = iris)", "object_list_2 <- list(x = mtcars, y = mtcars)", From 141e14f48fc433b73b7ce72ff349d4b5596fda20 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 7 Aug 2025 09:03:19 +0000 Subject: [PATCH 13/17] [skip style] [skip vbump] Restyle files --- tests/testthat/test-qenv_get_code.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index ba973813a..51624d9d7 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -290,8 +290,7 @@ testthat::describe("get_code for specific names", { ) } ) - testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", - { + testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", { code <- c( "object_list <- list(x = iris, y = iris)", "object_list_2 <- list(x = mtcars, y = mtcars)", From bae23a279762e3720472f3b6e5f8734fd3290c9c Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 7 Aug 2025 13:14:22 +0200 Subject: [PATCH 14/17] superlintr --- tests/testthat/test-qenv_get_code.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index 51624d9d7..ba973813a 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -290,7 +290,8 @@ testthat::describe("get_code for specific names", { ) } ) - testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", { + testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", + { code <- c( "object_list <- list(x = iris, y = iris)", "object_list_2 <- list(x = mtcars, y = mtcars)", From 2a2867779b9bffa7285387fff3f138f175d737ac Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 7 Aug 2025 13:15:16 +0200 Subject: [PATCH 15/17] superlintr --- tests/testthat/test-qenv_get_code.R | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index ba973813a..33f244e14 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -290,13 +290,14 @@ testthat::describe("get_code for specific names", { ) } ) - testthat::it("doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", - { - code <- c( - "object_list <- list(x = iris, y = iris)", - "object_list_2 <- list(x = mtcars, y = mtcars)", - "object_list_2[c('x')] <- c('string')", - "object_list[c('x')] <- c('string')" + testthat::it( + "doesn't consider function called on the lhs as a dependent in this call (dependency in further calls)", + { + code <- c( + "object_list <- list(x = iris, y = iris)", + "object_list_2 <- list(x = mtcars, y = mtcars)", + "object_list_2[c('x')] <- c('string')", + "object_list[c('x')] <- c('string')" ) q <- eval_code(qenv(), code = code) result <- get_code(q, names = "object_list") From 2690837485c76e723d5451ad162d40920b3f7adc Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 7 Aug 2025 11:17:25 +0000 Subject: [PATCH 16/17] [skip style] [skip vbump] Restyle files --- tests/testthat/test-qenv_get_code.R | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test-qenv_get_code.R b/tests/testthat/test-qenv_get_code.R index 33f244e14..282c72869 100644 --- a/tests/testthat/test-qenv_get_code.R +++ b/tests/testthat/test-qenv_get_code.R @@ -298,11 +298,12 @@ testthat::describe("get_code for specific names", { "object_list_2 <- list(x = mtcars, y = mtcars)", "object_list_2[c('x')] <- c('string')", "object_list[c('x')] <- c('string')" - ) - q <- eval_code(qenv(), code = code) - result <- get_code(q, names = "object_list") - testthat::expect_identical(result, paste(code[c(1, 4)], collapse = "\n")) - }) + ) + q <- eval_code(qenv(), code = code) + result <- get_code(q, names = "object_list") + testthat::expect_identical(result, paste(code[c(1, 4)], collapse = "\n")) + } + ) }) From 02b1b3b1ad9b2b3fcba0d2063df7d4f7bcb556a7 Mon Sep 17 00:00:00 2001 From: m7pr Date: Thu, 7 Aug 2025 13:50:12 +0200 Subject: [PATCH 17/17] Empty-Commit