Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result block - generate code #399

Open
JohnCoene opened this issue Aug 12, 2024 · 1 comment
Open

Result block - generate code #399

JohnCoene opened this issue Aug 12, 2024 · 1 comment
Assignees
Labels

Comments

@JohnCoene
Copy link
Member

Given the coming project makes heavy use of generated code (exporting the entire workspace to a document), and result block (all blocks but one will depend on the result of a data block): how do we generate code for this?

@DivadNojnarg
Copy link
Collaborator

DivadNojnarg commented Oct 14, 2024

@JohnCoene and @nbenn

I worked on something. In short, we extract the stack name from the result block field value, then extract the corresponding stack from the "reactive" workspace and generate the code from the linked stack:

generate_code.result_block <- function(x) {
  if (!is_initialized(x)) {
    return(quote(data.frame()))
  }
 # TBD: value() does not return the expected result. Can't use it
  val <- x$stack$value
  
  # When we initialize the workspace reactive_stack_directory does not exist.
  # 
  linked_stack <- if (is.null(attr(get_workspace(), "reactive_stack_directory"))) {
    get_workspace_stack(val)
  } else {
    attr(get_workspace(), "reactive_stack_directory")()[[val]]$stack
  }
  do.call(
    bquote,
    list(
      attr(x, "expr"),
      where = list(stack = generate_code(linked_stack)),
      splice = FALSE
    )
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants