MyNixOS website logo
Description

Rectangle Nested Lists.

A tool to rectangle a nested list, that is to convert it into a 'tibble'. This is done automatically or according to a given specification. A common use case is for nested lists coming from parsing 'JSON' files, or the 'JSON' responses of 'REST' 'APIs'. 'Rectangling' uses the 'vctrs' package, and therefore offers a wide support of vector types.

tibblify

Lifecycle:experimental CRANstatus Codecov testcoverage R buildstatus R-CMD-check

The goal of tibblify is to provide an easy way to convert a nested list into a tibble.

Installation

Install the released version of tibblify from CRAN:

install.packages("tibblify")

Install the development version of tibblify from GitHub:

# install.packages("pak")
pak::pak("wranglezone/tibblify")

Usage

To illustrate how tibblify() works, we’ll start with a list containing information about four GitHub users.

library(tibblify)
library(repurrrsive)

gh_users_small <- purrr::map(
  repurrrsive::gh_users,
  ~ .x[c("followers", "login", "url", "name", "location", "email", "public_gists")]
)

names(gh_users_small[[1]])
#> [1] "followers"    "login"        "url"          "name"         "location"    
#> [6] "email"        "public_gists"

We can rectangle gh_users_small automatically with tibblify():

tibblify(gh_users_small)
#> # A tibble: 6 × 7
#>   followers login       url                    name  location email public_gists
#>       <int> <chr>       <chr>                  <chr> <chr>    <chr>        <int>
#> 1       303 gaborcsardi https://api.github.co… Gábo… Chippen… csar…            6
#> 2       780 jennybc     https://api.github.co… Jenn… Vancouv… <NA>            54
#> 3      3958 jtleek      https://api.github.co… Jeff… Baltimo… <NA>            12
#> 4       115 juliasilge  https://api.github.co… Juli… Salt La… <NA>             4
#> 5       213 leeper      https://api.github.co… Thom… London,… <NA>            46
#> 6        34 masalmon    https://api.github.co… Maël… Barcelo… <NA>             0

We can avoid the note about the unspecified field by formally providing a spec starting with guess_tspec():

spec <- guess_tspec(gh_users_small, inform_unspecified = FALSE)
# Drop the unused email specification.
spec$fields$email <- NULL
tibblify(gh_users_small, spec = spec)
#> # A tibble: 6 × 6
#>   followers login       url                          name  location public_gists
#>       <int> <chr>       <chr>                        <chr> <chr>           <int>
#> 1       303 gaborcsardi https://api.github.com/user… Gábo… Chippen…            6
#> 2       780 jennybc     https://api.github.com/user… Jenn… Vancouv…           54
#> 3      3958 jtleek      https://api.github.com/user… Jeff… Baltimo…           12
#> 4       115 juliasilge  https://api.github.com/user… Juli… Salt La…            4
#> 5       213 leeper      https://api.github.com/user… Thom… London,…           46
#> 6        34 masalmon    https://api.github.com/user… Maël… Barcelo…            0

Learn more in vignette("tibblify").

Similar packages

  • jsonlite: jsonlite::fromJSON() is excellent for parsing JSON, but tibblify allows for strict specifications and can be faster for complex nested lists.
  • tidyr: tidyr::hoist() and tidyr::unnest_longer() allow for step-by-step rectangling. tibblify aims to rectangle the data in a single step based on a schema.
  • rrapply: Provides extended functionality for applying functions to nested lists, and can also be used to melt or prune lists.
  • tidyjson: Offers a grammar for manipulating JSON data.

Code of Conduct

Please note that the tibblify project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Metadata

Version

0.4.1

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows