knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

Lifecycle: stable Travis-CI Build Status AppVeyor Build Status Coverage Status CRAN status

unjoin

The goal of unjoin is to provide unjoin for data frames. This is exactly part of what tidyr::nest does, but with two differences:

Installation

Install unjoin from CRAN:

install.packages("unjoin")

You can install the development unjoin from github with:

# install.packages("devtools")
devtools::install_github("hypertidy/unjoin")

Example

This is a basic example which shows you how to unjoin a data frame.

library(unjoin)

unjoin(iris)

library(dplyr)
iris %>% unjoin(Species)

iris %>% unjoin(Species, Petal.Width)

This is used to build topological data structures, with a kind of inside-out version of a nested data frame. Whether it's of broader use is unclear.

There is a record here of some of the thinking that led to unjoin: https://github.com/r-gris/babelfish

The function unjoin replaces the method here: http://rpubs.com/cyclemumner/iout_nest

(d2 <- iris %>% unjoin(Species, Petal.Width))

We can chain unjoins together, but make sure not to repeat a key_col in one of these.

unjoin(iris, Species, key_col = "vertex") %>% unjoin(Petal.Width, vertex,  key_col = "branch")

Also, there's no escape hatch here, you can't "unjoin" your way to normal nirvana, each unjoin needs to carry the last unjoin-key with it, and you just end up with the big link table with no attributes. It needs some kind of group-semantic to cut the chain.


Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.



mdsumner/unjoin documentation built on May 10, 2020, 2 p.m.