Skip to content

Use defer to do some post-modification of parent return #276

Closed
@shaman-yellow

Description

@shaman-yellow

The case as following, but get 11 instead of 1100. Is this possible?

inner <- function(x, env = parent.frame(1)) {
  withr::defer(assign("x", get("x", envir = env) * 100, envir = env), env)
}
outer <- function(x) {
  inner(x)
  x <- x + 1
  return(x)
}
outer(10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions