Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blockr.code

lifecycle status coverage

The code export plugin module provided by ‘blockr.core’ is implemented to be as simple as possible. In order to do so, compromises were made in terms of code presentation, wrapping expressions with calls to base::with() and base::local(), even in cases where this is not strictly necessary. This alternative code-generation plugin is aimed at exporting more idiomatic code whenever possible.

Installation

You can install the development version of blockr.code from GitHub with:

# install.packages("pak")
pak::pak("BristolMyersSquibb/blockr.code")

Example

In this basic example we set up a board with 3 blocks.

library(blockr.core)
library(blockr.code)

serve(
  new_board(
    blocks = c(
      a = new_dataset_block("BOD"),
      b = new_dataset_block("ChickWeight"),
      c = new_merge_block("Time")
    ),
    links = c(
      ac = new_link("a", "c", "x"),
      bc = new_link("b", "c", "y")
    )
  ),
  plugins = custom_plugins(generate_flat_code())
)

This generates code as

b <- datasets::ChickWeight
a <- datasets::BOD

c <- merge(a, b, by = "Time", all.x = FALSE, all.y = FALSE)

instead of the same code as generated by the code plugin, where every block chunk is wrapped in a base::local() call.

b <- local(datasets::ChickWeight)
a <- local(datasets::BOD)

c <- local(merge(a, b, by = "Time", all.x = FALSE, all.y = FALSE))

All of this relies on blocks providing base::bquote()d expressions and announcing this by setting expr_type = "bquoted".

About

Idiomatic code generation for blockr

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages