knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

Sys.setenv(LANGUAGE = "en")

dibble

CRAN status Lifecycle: experimental R-CMD-check Codecov test coverage

A 'dibble' (derived from 'dimensional tibble') is a data frame consisting of arrays with dimension names, known as data cubes. The columns of the dibbles are classified into dimensions or measures, and the operations on the measures are broadcasted by dimension names.

Installation

# the released version from CRAN:
install.packages("dibble")

# the development version from GitHub:
# install.packages("devtools")
devtools::install_github("UchidaMizuki/dibble")

Examples

library(dibble)
library(dplyr)
library(tidyr)

Broadcasting

arr1 <- array(1:6, c(2, 3), list(axis1 = letters[1:2], axis2 = letters[1:3]))
arr2 <- array(1:2, 2, list(axis2 = letters[1:2]))

try(arr1 * arr2)

ddf1 <- as_dibble(arr1)
ddf2 <- as_dibble(arr2)

ddf1 * ddf2
# You can use broadcast() to suppress the warnings.
broadcast(ddf1 * ddf2, dim_names = c("axis1", "axis2"))

dplyr methods

dibble provides some dplyr methods as follows,

How to build a dibble

From a data.frame

df <- expand_grid(axis1 = letters[1:2], axis2 = letters[1:2]) |>
  mutate(value1 = row_number(), value2 = value1 * 2)

ddf <- df |>
  dibble_by(axis1, axis2)
ddf
# You can access the measures from the dibble with `$`.
ddf$value1

df <- expand_grid(
  tibble(axis1_key = letters[1:2], axis1_value = 1:2),
  tibble(axis2_key = letters[1:2], axis2_value = 1:2)
) |>
  mutate(value1 = row_number(), value2 = value1 * 2)

# You can `pack` several columns into one dimension (See `tidyr::pack()`).
df |>
  dibble_by(
    axis1 = c(axis1_key, axis1_value),
    axis2 = c(axis2_key, axis2_value),
    .names_sep = "_"
  )

From an array with dimension names or a vector

dibble provides some dplyr methods as follows,

# from an array with dimension names
arr <- array(1:4, c(2, 2), list(axis1 = letters[1:2], axis2 = letters[1:2]))

ddf1 <- as_dibble(arr)

# from a vector
ddf2 <- broadcast(1:4, list(axis1 = letters[1:2], axis2 = letters[1:2]))

arr
ddf1
ddf2


UchidaMizuki/dibble documentation built on June 1, 2025, 4:15 p.m.