Skip to content

Lazy Evaluation of Expressions in Same Configuration #57

@DavZim

Description

@DavZim

This is similar to #20 and #29 but this issue applies to the same configurations only.

Expectation

When I use config::get("val") I would expect that only "val" is evaluated and other items (even in the same configuration) are ignored.

Actual

When I use the code below, I see that all expressions of the current configuration are evaluated.

MWE

Setup

owd <- setwd(tempdir())
on.exit(setwd(owd))

yaml <- r"[
default:
  val1: 1
  expr1: !expr print("expr1 I should only be evaluated when I am used!")
  expr2: !expr print("expr2 I should only be evaluated when I am used!")

irrelevant:
  expr3: !expr print("expr3 I should only be evaluated when I am used!")
]"

writeLines(yaml, "config.yml")

Case 1: load all - works as expected

As I load "expr1" and "expr2" as well, I expect them to be evaluated!
Note that the "irrelevant" configuration is not evaluated (this would be #20 and #29).

res <- config::get()
#> [1] "expr1 I should only be evaluated when I am used!"
#> [1] "expr2 I should only be evaluated when I am used!"
str(res)
#> List of 3
#>  $ val1 : int 1
#>  $ expr1: chr "expr1 I should only be evaluated when I am used!"
#>  $ expr2: chr "expr2 I should only be evaluated when I am used!"
#>  - attr(*, "config")= chr "default"
#>  - attr(*, "file")= chr "/tmp/RtmpaoILIK/config.yml"
#>  - attr(*, "class")= chr "config"

Case 2: load only val1 - works unexpectedly (all expressions are evaluated)

I only load "val1", so I expect "expr1" and "expr2" to not be evaluated!
But as we can see below, they are being evaluated even though they are not used.

res <- config::get("val1")
#> [1] "expr1 I should only be evaluated when I am used!"
#> [1] "expr2 I should only be evaluated when I am used!"

str(res)
#>  int 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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