Skip to content

[Feature Request]: Support code dependency on a single expression with multiple assignments #251

@averissimo

Description

@averissimo

Feature description

Such as var1 <- var2 <- 2

pkgload::load_all("../teal.code")
#> ℹ Loading teal.code
code <- "var1 <- var2 <- 1"
td <- eval_code(qenv(), code)
get_code(td, names = "var1")
#> [1] "var1 <- var2 <- 1"
get_code(td, names = "var2")
#> Warning: Object(s) not found in code: var2.
#> [1] ""

Created on 2025-04-30 with reprex v2.1.1

See test suite below for test-driven development

testthat::describe("detects multiple assignments in single line", {
  testthat::it("<-", {
    # testthat::skip("Not implemented")
    code <- "var1 <- var2 <- 1"
    td <- eval_code(qenv(), code)

    testthat::expect_identical(get_code(td, names = "var1"), code)
    testthat::expect_identical(get_code(td, names = "var2"), code)
  })

  testthat::it("->", {
    code <- "1 -> var1 -> var2"
    td <- eval_code(qenv(), code)

    testthat::expect_identical(
      get_code(td, names = "var1"),
      as.character(parse(text = code, keep.source = TRUE))
    )

    testthat::expect_identical(get_code(td, names = "var1"), code)
    testthat::expect_identical(get_code(td, names = "var2"), code)
  })

  testthat::it("<- and ->", {
    code <- "var1 <- 1 -> var2"
    td <- eval_code(qenv(), code)

    testthat::expect_identical(get_code(td, names = "var1"), code)
    testthat::expect_identical(get_code(td, names = "var2"), code)
  })
})

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions