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

Copied/Generated code #442

Open
JohnCoene opened this issue Oct 24, 2024 · 1 comment
Open

Copied/Generated code #442

JohnCoene opened this issue Oct 24, 2024 · 1 comment
Labels
bug Something isn't working critical

Comments

@JohnCoene
Copy link
Member

The copied code is not valid as it does not substitute data.

E.g.: run app below, and try to run copied code.

library(shiny)
library(blockr)

new_blk <- function() {
  new_block(
    fields = list(),
    expr = quote({
      data$x <- 1L
      data
    }),
    class = c("blk", "transform_block")
  )
}

stack <- new_stack(
  new_dataset_block("cars"),
  new_blk()
)

serve_stack(stack)
@JohnCoene JohnCoene added bug Something isn't working critical labels Oct 24, 2024
@JohnCoene JohnCoene changed the title Copied code Copied/Generated code Oct 28, 2024
@nbenn
Copy link
Collaborator

nbenn commented Oct 28, 2024

@JohnCoene having a quick look at this, given that (transform) blocks are combined using magrittr pipes, standard syntax applies here. The following should work

new_blk <- function() {
  new_block(
    fields = list(),
    expr = quote({
      .$x <- 1L
      .
    }),
    class = c("blk", "transform_block")
  )
}

stack <- new_stack(
  new_dataset_block("cars"),
  new_blk()
)

serve_stack(stack)

Is this what you are after? Field values are substituted using bquote() syntax, but "data" does not receive special treatment. This is handled by magrittr. For sure this should be better documented!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical
Projects
None yet
Development

No branches or pull requests

2 participants