Learn R Programming

blockr.dplyr (version 0.1.0)

new_join_block: Join block constructor

Description

This block allows for joining of two data.frame objects with advanced multi-column support including same-name and different-name joins (see dplyr::left_join(), dplyr::inner_join(), etc.).

Usage

new_join_block(type = character(), by = character(), ...)

Value

A transform block object of class join_block.

Arguments

type

Join type (left_join, inner_join, right_join, full_join, semi_join, anti_join)

by

Column(s) to join on - can be character vector for same-name joins or named list for different-name joins

...

Forwarded to blockr.core::new_block()

Examples

Run this code
# Create a join block
new_join_block(type = "left_join")

if (interactive()) {
  library(blockr.core)
  library(blockr.dplyr)

  # Basic left join - automatically detects common columns
  serve(
    new_board(
      blocks = list(
        data1 = new_dataset_block(dataset = "band_members"),
        data2 = new_dataset_block(dataset = "band_instruments"),
        joined = new_join_block(type = "left_join")
      ),
      links = links(
        from = c("data1", "data2"),
        to = c("joined", "joined"),
        input = c("x", "y")
      )
    )
  )

  # Inner join with explicit join column
  serve(
    new_board(
      blocks = list(
        data1 = new_dataset_block(dataset = "band_members"),
        data2 = new_dataset_block(dataset = "band_instruments"),
        joined = new_join_block(type = "inner_join", by = "name")
      ),
      links = links(
        from = c("data1", "data2"),
        to = c("joined", "joined"),
        input = c("x", "y")
      )
    )
  )

  # Right join - keep all rows from right dataset
  serve(
    new_board(
      blocks = list(
        data1 = new_dataset_block(dataset = "band_members"),
        data2 = new_dataset_block(dataset = "band_instruments"),
        joined = new_join_block(type = "right_join")
      ),
      links = links(
        from = c("data1", "data2"),
        to = c("joined", "joined"),
        input = c("x", "y")
      )
    )
  )

  # Anti join - find rows in left without matches in right
  serve(
    new_board(
      blocks = list(
        data1 = new_dataset_block(dataset = "band_members"),
        data2 = new_dataset_block(dataset = "band_instruments"),
        joined = new_join_block(type = "anti_join")
      ),
      links = links(
        from = c("data1", "data2"),
        to = c("joined", "joined"),
        input = c("x", "y")
      )
    )
  )
}

Run the code above in your browser using DataLab