Package {tibblify}


Title: Rectangle Nested Lists
Version: 0.4.0
Description: 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.
License: MIT + file LICENSE
URL: https://tibblify.wrangle.zone, https://github.com/wranglezone/tibblify
BugReports: https://github.com/wranglezone/tibblify/issues
Depends: R (≥ 4.1.0)
Imports: cli (≥ 3.6.2), glue, lifecycle, purrr (≥ 1.0.2), rlang (≥ 1.2.0), tibble (≥ 3.2.1), tidyselect (≥ 1.2.0), vctrs (≥ 0.7.2), withr (≥ 2.5.2)
Suggests: covr (≥ 3.6.1), jsonlite (≥ 1.8.0), knitr (≥ 1.40), memoise (≥ 2.0.1), repurrrsive, rmarkdown (≥ 2.16), spelling (≥ 2.2), stbl, testthat (≥ 3.1.4), tidyr, yaml (≥ 2.3.6)
LinkingTo: vctrs
VignetteBuilder: knitr
Config/roxygen2/version: 8.0.0
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
NeedsCompilation: yes
Packaged: 2026-05-08 18:00:43 UTC; jonth
Author: Jon Harmon ORCID iD [aut, cre], Maximilian Girlich [aut, cph], Kirill Müller [ctb]
Maintainer: Jon Harmon <jonthegeek@gmail.com>
Repository: CRAN
Date/Publication: 2026-05-09 16:30:02 UTC

tibblify: Rectangle Nested Lists

Description

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.

Author(s)

Maintainer: Jon Harmon jonthegeek@gmail.com (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Abort when x is neither an object nor a list of objects

Description

Abort when x is neither an object nor a list of objects

Usage

.abort_not_tibblifiable(x, arg = caller_arg(x), call = caller_env())

Arguments

x

(any) The object to check.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

Nothing. Called for its side effect of throwing an error.


Accumulate ancestor chains for a single snapshot level

Description

Accumulate ancestor chains for a single snapshot level

Usage

.accumulate_snapshot_level(cur_ancestors, snapshot, id_col, call)

Arguments

cur_ancestors

(list) A list of ancestor vectors for the current level, one per row.

snapshot

(list) A single snapshot object with elements data, ns, parent_ids, and child_sizes.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

A list of ancestor vectors for the next level, where each vector is the ancestor vector of the parent row with the parent id appended.


Apply nesting at a single tree level

Description

Apply nesting at a single tree level

Usage

.apply_nest_lvl(x_split, cur_lvl, children, parent_col, id_col, children_to)

Arguments

x_split

(data.frame) A data frame that has been split using vctrs::vec_split().

cur_lvl

(integer(1)) The key being split.

children

(data.frame) The data frame that contains potential children.

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

children_to

(character(1)) The column name in which to store the children.

Value

A data frame of parents with their children nested into a column.


Apply nesting across all tree levels

Description

Apply nesting across all tree levels

Usage

.apply_nesting(
  x,
  id_col,
  parent_col,
  children_to,
  id_col_name,
  call = caller_env()
)

Arguments

x

(any) The object to check.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

children_to

(character(1)) The column name in which to store the children.

id_col_name

(character(1)) The name of the column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

A nested data frame with root elements at the top level.


Apply required flags to a list of tib fields

Description

Apply required flags to a list of tib fields

Usage

.apply_required(fields, required)

Arguments

fields

(list) A named list of tib field specs.

required

(character) Names of required fields.

Value

(list) The same fields list with required = TRUE set on the named fields.


Rename list elements back to their original spec keys

Description

Reverses tibblify's field renaming by mapping column names back to the original keys defined in spec.

Usage

.apply_spec_renaming(x, spec, call = caller_env())

Arguments

x

(any) The object to check.

spec

(tspec or NULL) A spec object describing the structure of x.

call

(environment) The environment to use for error messages.

Value

A named list with elements keyed by the original spec keys.


Assemble the ancestors column for unnest_tree() output

Description

Assemble the ancestors column for unnest_tree() output

Usage

.assemble_ancestors_col(out, ancestors_to, tree_levels, call)

Arguments

out

(data.frame) The partially assembled output.

ancestors_to

(character(1)) The column name (NULL by default) in which to store the ids of the ancestors of a deeply nested child. Use NULL if you don't need this information.

tree_levels

(list) The object returned by .collect_tree_levels(), containing level_data, out_ptype, level_sizes, level_parent_ids, and level_ancestors.

call

(environment) The environment to use for error messages.

Value

A vector of ancestor ids with the same length as nrow(out).


Assemble the level column for unnest_tree() output

Description

Assemble the level column for unnest_tree() output

Usage

.assemble_level_col(out, level_to, level_data, call)

Arguments

out

(data.frame) The partially assembled output.

level_data

(list) Data frames collected at each tree level, without the child column.

call

(environment) The environment to use for error messages.

Value

An integer vector of levels with the same length as nrow(out).


Assemble the parent id column for unnest_tree() output

Description

Assemble the parent id column for unnest_tree() output

Usage

.assemble_parent_col(out, parent_to, tree_levels, id_col, call)

Arguments

out

(data.frame) The partially assembled output.

parent_to

(character(1)) The column name ("parent" by default) in which to store the parent id of an observation. Use NULL if you don't need this information.

tree_levels

(list) The object returned by .collect_tree_levels(), containing level_data, out_ptype, level_sizes, level_parent_ids, and level_ancestors.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

A vector of parent ids with the same type as out[[id_col]] and the same length as nrow(out).


Assemble the final output from per-level data

Description

Assemble the final output from per-level data

Usage

.assemble_tree_output(
  tree_levels,
  id_col,
  level_to,
  parent_to,
  ancestors_to,
  call = caller_env()
)

Arguments

tree_levels

(list) The object returned by .collect_tree_levels(), containing level_data, out_ptype, level_sizes, level_parent_ids, and level_ancestors.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

level_to

(character(1)) The column name ("level" by default) in which to store the level of an observation. Use NULL if you don't need this information.

parent_to

(character(1)) The column name ("parent" by default) in which to store the parent id of an observation. Use NULL if you don't need this information.

ancestors_to

(character(1)) The column name (NULL by default) in which to store the ids of the ancestors of a deeply nested child. Use NULL if you don't need this information.

call

(environment) The environment to use for error messages.

Value

(data.frame) The assembled output with metadata columns appended.


Backtick-wrap a character vector

Description

Backtick-wrap a character vector

Usage

.backtick(x)

Arguments

x

(character) A character vector to backtick-wrap.

Value

A character vector with each element wrapped in backticks and any existing backticks escaped with a backslash.


Build ancestor chains across levels using accumulate

Description

Build ancestor chains across levels using accumulate

Usage

.build_level_ancestors(snapshots, id_col, call)

Arguments

snapshots

(list) The object returned by .walk_tree_levels().

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

A list of length length(snapshots), where element k is a list of ancestor vectors (one per row at level k).


Convert POSIXlt to POSIXct

Description

Convert POSIXlt to POSIXct

Usage

.cast_posixlt_ptype(x)

Arguments

x

(any) The object to check.

Value

An object of class POSIXct if the input is POSIXlt (to be in line with https://github.com/r-lib/vctrs/issues/1576), otherwise the input unchanged.


Validate that arguments are different

Description

Validate that arguments are different

Usage

.check_arg_different(arg, ..., arg_name = caller_arg(arg), call = caller_env())

Arguments

arg

(any) The value to compare against ....

...

Other arguments that arg must differ from.

arg_name

(character(1)) The argument name shown in error messages.

call

(environment) The environment to use for error messages.

Value

arg (invisibly). Throws an error if any values are identical.


Confirm that children_to is usable

Description

Confirm that children_to is usable

Usage

.check_children_to(children_to, id_col, parent_col, call = caller_env())

Arguments

children_to

(character(1)) The column name in which to store the children.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

call

(environment) The environment to use for error messages.

Value

The input children_to object as a string.


Check that a column name does not already exist in a data frame

Description

Check that a column name does not already exist in a data frame

Usage

.check_col_new(
  x,
  col_name,
  col_arg = caller_arg(col_name),
  x_arg = "x",
  call = caller_env()
)

Arguments

x

(data.frame) The data frame to unnest.

col_name

(character(1)) The name of the column.

col_arg

(character(1)) The name of the col argument, used for error messages.

x_arg

(character(1)) Data frame argument name used in error messages.

call

(environment) The environment to use for error messages.

Value

x (invisibly). Throws an error if col_name is already a column of x.


Check that a column has no duplicate values

Description

Check that a column has no duplicate values

Usage

.check_col_value_duplicates(x, x_arg, call = caller_env())

Arguments

x

(any) The object to check.

x_arg

(character(1)) The name of the x argument. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

The input x.


Check that a column has no missing values

Description

Check that a column has no missing values

Usage

.check_col_values_missing(x, x_arg, call = caller_env())

Arguments

x

(any) The object to check.

x_arg

(character(1)) The name of the x argument. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

The input x.


Check that id column has no missing or duplicate values

Description

Check that id column has no missing or duplicate values

Usage

.check_id(x, x_arg, call = caller_env())

Arguments

x

(any) The object to check.

x_arg

(character(1)) The name of the x argument. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

The input x.


Check that id column has no missing or duplicate values

Description

Check that id column has no missing or duplicate values

Usage

.check_id_col(id_col, x, call = caller_env())

Arguments

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

x

(any) The object to check.

call

(environment) The environment to use for error messages.

Value

The integer index of the id column.


Confirm that an object is a data frame

Description

Confirm that an object is a data frame

Usage

.check_is_df(x, x_arg = caller_arg(x), call = caller_env())

Arguments

x

(any) The object to check.

x_arg

(character(1)) The name of the x argument. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

The input object.


Check if a key is valid

Description

Check if a key is valid

Usage

.check_key(.key, .call = caller_env())

Arguments

.key

(character) The path of names to the field in the object.

.call

(environment) The environment to use for error messages.

Value

(NULL) Throws an error if invalid.


Check that a key is valid for untibblify

Description

Validates that key is a length-1 character string by chaining .check_key_length_1() and .check_key_is_character().

Usage

.check_key_can_untibblify(key, call = caller_env())

Arguments

key

(character) The spec key to validate.

call

(environment) The environment to use for error messages.

Value

key if valid; otherwise throws an error.


Check that a key is a character string

Description

Check that a key is a character string

Usage

.check_key_is_character(key, call = caller_env())

Arguments

key

(character) The spec key to validate.

call

(environment) The environment to use for error messages.

Value

key if valid; otherwise throws an error.


Check that a key has length 1

Description

Check that a key has length 1

Usage

.check_key_length_1(key, call = caller_env())

Arguments

key

(character) The spec key to validate.

call

(environment) The environment to use for error messages.

Value

key if valid; otherwise throws an error.


Validate that an input is a list

Description

Validate that an input is a list

Usage

.check_list(
  x,
  ...,
  allow_null = FALSE,
  arg = caller_arg(x),
  call = caller_env()
)

Arguments

x

(any) The object to check.

...

Additional arguments passed to rlang::stop_input_type().

allow_null

(logical(1)) Whether NULL is accepted.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

NULL (invisibly) if valid; otherwise throws an error.


Check that all elements have assigned tree levels

Description

Check that all elements have assigned tree levels

Usage

.check_lvls(lvls, call = caller_env())

Arguments

lvls

(integer) A vector of levels.

call

(environment) The environment to use for error messages.

Value

The input lvls.


Abort for missing names

Description

Abort for missing names

Usage

.check_named(x, call)

Arguments

x

(any) The object to check.

call

(environment) The environment to use for error messages.

Value

NULL (invisibly).


Abort for duplicate names

Description

Abort for duplicate names

Usage

.check_names_not_duplicated(x, call)

Arguments

x

(any) The object to check.

call

(environment) The environment to use for error messages.

Value

NULL (invisibly).


Check that .names_to is valid for the given input form

Description

Check that .names_to is valid for the given input form

Usage

.check_names_to(.names_to, .input_form, .call = caller_env())

Arguments

.names_to

(character(1) or NULL) The name of the column in the output which will contain the names of top-level elements of the input named list. If NULL, the default, no name column is created.

.input_form

(character(1)) The input form of data-frame-like lists. Can be one of:

  • "rowmajor": The default. The input is a named list of rows.

  • "colmajor": The input is a named list of columns.

.call

(environment) The environment to use for error messages.

Value

NULL (invisibly).


Abort if x is a data frame

Description

Abort if x is a data frame

Usage

.check_not_df(x, call)

Arguments

x

(any) The object to check.

call

(environment) The environment to use for error messages.

Value

x (invisibly).


Abort if x is not a list of objects

Description

Abort if x is not a list of objects

Usage

.check_object_list(x, arg = caller_arg(x), call = caller_env())

Arguments

x

(any) The object to check.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

x (invisibly). Called for side effect.


Abort for missing or duplicate names

Description

Abort for missing or duplicate names

Usage

.check_object_names(x, call)

Arguments

x

(any) The object to check.

call

(environment) The environment to use for error messages.

Value

NULL (invisibly).


Ensure the OpenAPI version is supported

Description

Ensure the OpenAPI version is supported

Usage

.check_openapi_version(openapi_spec)

Arguments

openapi_spec

(list) A parsed OpenAPI specification.

Value

The input openapi_spec if the version is supported.


Check that parent column is valid and distinct from id column

Description

Check that parent column is valid and distinct from id column

Usage

.check_parent_col(parent_col, x, id_col, id_col_name, call = caller_env())

Arguments

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

x

(any) The object to check.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

id_col_name

(character(1)) The name of the column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

The integer index of the parent column.


Check that parent ids aren't missing

Description

Check that parent ids aren't missing

Usage

.check_parent_id_missing(parent_ids, ids, call = caller_env())

Arguments

parent_ids

(character or integer) The parent ids to check.

ids

(character or integer) The potential child ids to compare against.

call

(environment) The environment to use for error messages.

Value

The input parent_ids.


Confirm that parent ids are usable

Description

Confirm that parent ids are usable

Usage

.check_parent_ids(x, parent_col, id_col, id_col_name, call = caller_env())

Arguments

x

(any) The object to check.

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

id_col_name

(character(1)) The name of the column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

The parent ids, cast to the same type as ids.


Check and determine whether to print names for tibblifying

Description

Check and determine whether to print names for tibblifying

Usage

.check_print_names_arg(names)

Arguments

names

(logical(1)) Should names be printed even if they can be deduced from the spec?

Value

A logical value indicating whether to print names for tibblifying, based on the provided names argument or the tibblify.print_names option if names is NULL.


Check that no element is its own parent

Description

Check that no element is its own parent

Usage

.check_self_reference(parent_ids, ids, call = caller_env())

Arguments

parent_ids

(character or integer) The parent ids to check.

ids

(character or integer) The potential child ids to compare against.

call

(environment) The environment to use for error messages.

Value

The input parent_ids.


Check dots arguments for tspec combine

Description

Check dots arguments for tspec combine

Usage

.check_tspec_combine_dots(..., .call = caller_env())

Arguments

...

Specifications to combine.

.call

(environment) The environment to use for error messages.

Value

(list) A list of specifications.


Check spec types for compatibility

Description

Check spec types for compatibility

Usage

.check_tspec_combine_type(spec_list, .call = caller_env())

Arguments

spec_list

(list) A list of specifications.

.call

(environment) The environment to use for error messages.

Value

(character(1)) The type of the specifications.


Validate an output column name and check it differs from prior names

Description

Validate an output column name and check it differs from prior names

Usage

.check_unnest_col_diff(
  col_name,
  x,
  ...,
  col_arg = caller_arg(col_name),
  call = caller_env()
)

Arguments

col_name

(character(1)) The name of the column.

x

(data.frame) The data frame to unnest.

...

Already-reserved column names that col_name must differ from.

col_arg

(character(1)) The name of the col argument, used for error messages.

call

(environment) The environment to use for error messages.

Value

col_name or NULL.


Validate and normalize an output column name

Description

Validate and normalize an output column name

Usage

.check_unnest_col_name(
  col_name,
  x,
  col_arg = caller_arg(col_name),
  call = caller_env()
)

Arguments

col_name

(character(1)) The name of the column.

x

(data.frame) The data frame to unnest.

col_arg

(character(1)) The name of the col argument, used for error messages.

call

(environment) The environment to use for error messages.

Value

col_name (cast to character) or NULL.


Choose native ptype class

Description

Choose native ptype class

Usage

.choose_native_ptype(.ptype, .class, .fields)

Arguments

.ptype

(vector(0)) A prototype of the desired output type of the field.

.class

(character or NULL) Additional classes for the collector.

.fields

(list) The fields list.

Value

(character or NULL) The native ptype class name.


Guess whether a field is required across a list of data frames

Description

Guess whether a field is required across a list of data frames

Usage

.col_guess_required(col_name, df_list)

Arguments

col_name

(character(1)) The column name to check.

df_list

(list) A list of data frames.

Value

(logical(1)) TRUE if col_name is present in every data frame, FALSE otherwise.


Convert a column to a tib field specification

Description

Convert a column to a tib field specification

Usage

.col_to_spec(col, name, empty_list_unspecified, local_env)

Arguments

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib field specification.


Convert a df-typed list column to a tib_df specification

Description

Delegates to .list_of_col_to_spec_df() or .non_list_of_col_to_spec_df() based on whether col is a list_of() column.

Usage

.col_to_spec_df(
  ptype,
  col,
  name,
  list_of_col,
  empty_list_unspecified,
  local_env
)

Arguments

ptype

(vector(0)) A prototype of the desired output type of the field.

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

name

(character(1)) The name of the field.

list_of_col

(logical(1)) Whether col is a list_of() column.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib_df() specification.


Collapse expressions with padding and optional multi-line formatting

Description

Collapse expressions with padding and optional multi-line formatting

Usage

.collapse_with_pad(x, multi_line, nchar_prefix = 0, width)

Arguments

x

(list) Expressions to collapse.

multi_line

(logical(1)) Should the output be formatted across multiple lines? For example, should each element of even a short list be displayed on its own line?

nchar_prefix

(integer(1)) The number of characters that are "used up" by any prefix portions of the output. Used to determine whether the output will fit on a single line or if it should be wrapped across multiple lines.

width

(integer(1)) The width (in number of characters) of text output to generate.

Value

A single string with the expressions collapsed, either on a single line or wrapped across multiple lines with indentation.


Collect formatted field parts

Description

Collect formatted field parts

Usage

.collect_parts(fields, width, force_names, args)

Arguments

fields

(list or NULL) Fields to format.

width

(integer(1)) The width (in number of characters) of text output to generate.

force_names

(logical(1)) Should names be printed even if they can be deduced from the spec?

args

(list or NULL) Additional arguments to format and display before fields.

Value

A character vector of formatted field parts.


Traverse the tree and collect per-level data

Description

Traverse the tree and collect per-level data

Usage

.collect_tree_levels(
  x,
  id_col,
  child_col,
  parent_to,
  ancestors_to,
  call = caller_env()
)

Arguments

x

(data.frame) The root-level data frame.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

child_col

(character(1), integer(1), or symbol) The column that contains the children of an observation. This column must be a list where each element is either NULL or a data frame with the same columns as x.

parent_to

(character(1)) The column name ("parent" by default) in which to store the parent id of an observation. Use NULL if you don't need this information.

ancestors_to

(character(1)) The column name (NULL by default) in which to store the ids of the ancestors of a deeply nested child. Use NULL if you don't need this information.

call

(environment) The environment to use for error messages.

Value

A named list with elements level_data, out_ptype, level_sizes, level_parent_ids, and level_ancestors.


Combine processed simple and complex fields

Description

Combine processed simple and complex fields

Usage

.combine_processed_fields(
  spec_simple,
  spec_complex,
  coll_locations,
  is_sub,
  first_keys
)

Arguments

spec_simple

(list) Processed simple fields.

spec_complex

(list) Processed complex fields.

coll_locations

(integer) A numeric vector of locations.

is_sub

(logical) Which fields are sub-fields?

first_keys

(character) First keys of the complex fields.

Value

A list with fields, locations, and keys.


Map to a character vector

Description

Map to a character vector

Usage

.compat_map_chr(x, .f, ...)

Arguments

x

(any) The object to check.

.f

(function) Function to apply to each element of x.

...

Additional arguments passed to .f.

Value

(character) The mapped character vector.


Format a data frame column reference for error messages

Description

Format a data frame column reference for error messages

Usage

.data_field_name(col_name)

Value

A string in the form "x$col".


Handle deprecated arguments

Description

Handle deprecated arguments

Usage

.deprecate_arg(
  good_arg,
  bad_arg,
  fn_name = rlang::call_name(rlang::caller_call()),
  pkg_version = "0.4.0",
  good_arg_name = rlang::caller_arg(good_arg),
  bad_arg_name = rlang::caller_arg(bad_arg),
  .call = rlang::caller_env(),
  user_env = rlang::caller_env(2)
)

Arguments

good_arg

(any) The value of the new argument.

bad_arg

(any) The value of the deprecated argument.

fn_name

(character(1)) Name of the calling function.

pkg_version

(character(1)) Package version when deprecation occurred.

good_arg_name

(character(1)) Name of the new argument.

bad_arg_name

(character(1)) Name of the deprecated argument.

.call

(environment) The environment to use for error messages.

user_env

(environment) The environment from which the calling function is being called.

Value

(any) The value to use.


Convert a nested data frame column to a tib_row specification

Description

Convert a nested data frame column to a tib_row specification

Usage

.df_col_to_spec(col, name, empty_list_unspecified, local_env)

Arguments

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib_row() specification.


Guess whether each field is required in a df-typed list column

Description

Guess whether each field is required in a df-typed list column

Usage

.df_guess_required(fields_spec, col, ptype)

Arguments

fields_spec

(list) A named list of tib field specifications.

col

(list) A list column whose elements are data frames.

ptype

(vector(0)) A prototype of the desired output type of the field.

Value

fields_spec with ⁠$required⁠ updated for each field.


Wrap a string in double quotes if it's not NULL

Description

Wrap a string in double quotes if it's not NULL

Usage

.double_quote(x)

Arguments

x

(character(1) or NULL) A string to wrap in double quotes, or NULL.

Value

The input string wrapped in double quotes if it was not NULL, or NULL.


Remove empty lists from an object

Description

Remove empty lists from an object

Usage

.drop_empty_lists(x)

Arguments

x

(any) The object to check.

Value

The input object with empty lists removed. If any were removed, the returned object has an attribute had_empty_lists set to TRUE.


Convert a path element to a subset string

Description

Convert a path element to a subset string

Usage

.element_subset_string(elt)

Arguments

elt

(character or integer) An element of a path.

Value

A string representing a subset operation for the given path element, such as "$a" or "[[1]]".


Evaluate and extract a single column selection

Description

Evaluate and extract a single column selection

Usage

.eval_pull(x, col, col_arg, call = caller_env())

Arguments

x

(any) The object to check.

col

(character, integer, or symbol) Defused R code describing a selection according to the tidyselect syntax.

col_arg

(character(1)) The name of the col argument, used for error messages.

call

(environment) The environment to use for error messages.

Value

An integer index of the selected column, named by the column name.


Extract and validate the children list from a level data frame

Description

Extract and validate the children list from a level data frame

Usage

.extract_children(x, child_col, call = caller_env())

Arguments

x

(data.frame) Current level data frame.

child_col

(character(1), integer(1), or symbol) The column that contains the children of an observation. This column must be a list where each element is either NULL or a data frame with the same columns as x.

call

(environment) The environment to use for error messages.

Value

(list) The children list extracted from x[[child_col]].


Create a minimal tibble from a list

Description

Create a minimal tibble from a list

Usage

.fast_tibble(x, n = NULL)

Arguments

x

(list) A named list of equal-length vectors.

n

(integer(1) or NULL) Number of rows; inferred from x if NULL.

Value

(tbl_df) A tibble constructed directly from x.


Extract tib fields from schema properties

Description

Extract tib fields from schema properties

Usage

.fields_from_schema_properties(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A named list of tib field specs corresponding to the schema properties, with required flags applied.


Finalize a tibblify object

Description

Finalize a tibblify object

Usage

.finalize_tspec_object(field_spec, field)

## S3 method for class 'tib_collector'
.finalize_tspec_object(field_spec, field)

## S3 method for class 'tib_scalar'
.finalize_tspec_object(field_spec, field)

## S3 method for class 'tib_row'
.finalize_tspec_object(field_spec, field)

Arguments

field_spec

(tib_collector) A field specification.

field

(any) The field value.

Value

The finalized field spec.


Flatten nested field specifications

Description

Flatten nested field specifications

Usage

.flatten_fields(.fields)

Arguments

.fields

(list) A list of field specifications, typically created by ⁠tib_*()⁠.

Value

A flattened, named list of field specifications.


Forget memoised version of .parse_schema

Description

Forget memoised version of .parse_schema

Usage

.forget_parse_schema_memoised()

Value

If memoise is installed, TRUE if the function is memoised, FALSE otherwise. If memoise is not installed, NULL (invisibly).


Format field parts with canonical names

Description

Format field parts with canonical names

Usage

.format_field_canonical_names(fields, width, force_names)

Arguments

fields

(list or NULL) Fields to format.

width

(integer(1)) The width (in number of characters) of text output to generate.

force_names

(logical(1)) Should names be printed even if they can be deduced from the spec?

Value

A character vector of formatted field parts with canonical names potentially suppressed.


Format fields to print a function call

Description

Format fields to print a function call

Usage

.format_fields(f_name, fields, width, force_names, args = NULL)

Arguments

f_name

(character(1)) The (possibly ANSI-colored) function name.

fields

(list or NULL) Fields to format.

width

(integer(1)) The width (in number of characters) of text output to generate.

force_names

(logical(1)) Should names be printed even if they can be deduced from the spec?

args

(list or NULL) Additional arguments to format and display before fields.

Value

A single string with the formatted fields.


Format a fill value as a character string

Description

Format a fill value as a character string

Usage

.format_fill(x)

## Default S3 method:
.format_fill(x)

## S3 method for class 'Date'
.format_fill(x)

Arguments

x

A fill value.

Value

(character(1)) An R expression string representing x.


Format the .fill argument for display

Description

Format the .fill argument for display

Usage

.format_fill_arg(x, .fill)

Arguments

x

A tibblify collector object.

.fill

(vector or NULL) Optionally, a value to use if the field does not exist. Note: this value must match the .ptype_inner of the field (the value before any transformation), not the .ptype.

Value

(character(1) or NULL) The formatted fill string, or NULL if the argument should be omitted.


Format a ptype object as a character string

Description

Format a ptype object as a character string

Usage

.format_ptype(x)

## Default S3 method:
.format_ptype(x)

## S3 method for class 'difftime'
.format_ptype(x)

## S3 method for class 'Date'
.format_ptype(x)

## S3 method for class 'POSIXct'
.format_ptype(x)

Arguments

x

(ptype) A prototype object.

Value

(character(1)) An R expression string representing x.


Format the .ptype argument for display

Description

Format the .ptype argument for display

Usage

.format_ptype_arg(x)

Arguments

x

A tibblify collector object.

Value

(character(1) or NULL) The formatted ptype string, or NULL if the argument should be omitted.


Format the .ptype_inner argument for display

Description

Format the .ptype_inner argument for display

Usage

.format_ptype_inner(x, .ptype_inner)

Arguments

x

A tibblify collector object.

.ptype_inner

(vector(0)) A prototype of the input field.

Value

(character(1) or NULL) The formatted .ptype string, or NULL if the argument should be omitted.


Return the display function name for a collector

Description

Return the display function name for a collector

Usage

.format_tib_f(x)

## S3 method for class 'tib_unspecified'
.format_tib_f(x)

## S3 method for class 'tib_scalar_logical'
.format_tib_f(x)

## S3 method for class 'tib_scalar_integer'
.format_tib_f(x)

## S3 method for class 'tib_scalar_numeric'
.format_tib_f(x)

## S3 method for class 'tib_scalar_character'
.format_tib_f(x)

## S3 method for class 'tib_scalar_date'
.format_tib_f(x)

## S3 method for class 'tib_scalar_chr_date'
.format_tib_f(x)

## S3 method for class 'tib_scalar'
.format_tib_f(x)

## S3 method for class 'tib_vector_logical'
.format_tib_f(x)

## S3 method for class 'tib_vector_integer'
.format_tib_f(x)

## S3 method for class 'tib_vector_numeric'
.format_tib_f(x)

## S3 method for class 'tib_vector_character'
.format_tib_f(x)

## S3 method for class 'tib_vector_date'
.format_tib_f(x)

## S3 method for class 'tib_vector_chr_date'
.format_tib_f(x)

## S3 method for class 'tib_vector'
.format_tib_f(x)

## S3 method for class 'tib_variant'
.format_tib_f(x)

## S3 method for class 'tib_row'
.format_tib_f(x)

## S3 method for class 'tib_df'
.format_tib_f(x)

## S3 method for class 'tib_recursive'
.format_tib_f(x)

## Default S3 method:
.format_tib_f(x)

Arguments

x

A tibblify collector object.

Value

(character(1)) The (possibly ANSI-colored) function name string.


Build the formatted argument string for a collector call

Description

Build the formatted argument string for a collector call

Usage

.format_tib_parts(
  f_name,
  x,
  ...,
  .fill = NULL,
  .ptype_inner = NULL,
  .transform = NULL,
  multi_line = FALSE,
  nchar_indent = 0,
  width = NULL,
  names = FALSE
)

Arguments

f_name

(character(1)) The (possibly ANSI-colored) function name.

x

A tibblify collector object.

...

Additional named arguments to include verbatim in the output, forwarded from the calling ⁠format.*⁠ method.

.fill

(vector or NULL) Optionally, a value to use if the field does not exist. Note: this value must match the .ptype_inner of the field (the value before any transformation), not the .ptype.

.ptype_inner

(vector(0)) A prototype of the input field.

.transform

(function or NULL) A function to apply to the whole vector after casting to .ptype_inner.

multi_line

(logical(1)) Should the output be formatted across multiple lines? For example, should each element of even a short list be displayed on its own line?

nchar_indent

(integer(1)) The number of (additional) characters that will be used to indent the output when multi_line = TRUE. Primarily for internal use when formatting is applied recursively.

width

(integer(1)) The width (in number of characters) of text output to generate.

names

(logical(1)) Should names be printed even if they can be deduced from the spec?

Value

(character(1)) A string of comma-separated, possibly wrapped arguments ready to be placed inside the parentheses of the collector call.


Prep unspecified paths for messaging

Description

Prep unspecified paths for messaging

Usage

.format_unspecified_paths(path_list, path = character())

Arguments

path_list

(list) A list of tib_unspecified() objects and objects containing tib_unspecified() objects.

path

(character) Current path prefix.

Value

The formatted paths as character.


Determine the type of an OpenAPI schema object

Description

Determine the type of an OpenAPI schema object

Usage

.get_openapi_type(schema)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

Value

(character(1)) The type string, one of "object", "array", "string", "integer", "boolean", "number", or "variant".


Find the common ptype of a list of objects

Description

Find the common ptype of a list of objects

Usage

.get_ptype_common(x, empty_list_unspecified)

Arguments

x

(any) The object to check.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

Value

A list with component has_common_ptype (TRUE if so, FALSE otherwise) and optional components ptype (an object representing the common ptype, if there is one) and had_empty_lists (TRUE if empty_list_unspecified is TRUE and the x input had such empty lists).


Determine which fields are required in an object list

Description

Determine which fields are required in an object list

Usage

.get_required(x, sample_size = 10000)

Arguments

x

(any) The object to check.

sample_size

(integer(1)) Maximum number of records to sample when x is large.

Value

A named logical vector indicating which fields are present in every element of x.


Find unspecified fields

Description

Find unspecified fields

Usage

.get_unspecified_paths(spec)

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

Value

A list of tib_unspecified() objects and objects containing tib_unspecified() objects.


Guess the field spec for a single object field

Description

Dispatches to the appropriate helper based on the detected type of value.

Usage

.guess_object_field_spec(
  value,
  name,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib field specification.


Guess the field spec for a data-frame-typed field

Description

Guess the field spec for a data-frame-typed field

Usage

.guess_object_field_spec_df(value, name, empty_list_unspecified, local_env)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib_df field specification.


Expand an object list into a tib spec

Description

Expand an object list into a tib spec

Usage

.guess_object_field_spec_expand_fields(
  value,
  empty_list_unspecified,
  simplify_list,
  local_env,
  ...,
  tib_fn = tib_df,
  fields_fn = .guess_object_list_spec
)

Arguments

value

(list) An object list whose fields will be guessed.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

...

Additional arguments passed to tib_fn.

tib_fn

(function) The tib constructor to wrap the fields in (e.g. tib_df() or tib_row()).

fields_fn

(function) The function used to generate field specs from value; defaults to .guess_object_list_spec().

Value

A tib spec created by tib_fn.


Expand an object list into a tib_df spec

Description

Expand an object list into a tib_df spec

Usage

.guess_object_field_spec_expand_fields_df(
  value,
  empty_list_unspecified,
  simplify_list,
  local_env,
  ...,
  tib_fn = tib_df
)

Arguments

value

(list) An object list whose fields will be guessed.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

...

Additional arguments passed to tib_fn.

tib_fn

(function) The tib constructor to wrap the fields in; defaults to tib_df().

Value

A tib_df() spec, with .names_to set when value is named and non-empty.


Guess the field spec for a nested object field

Description

Guess the field spec for a nested object field

Usage

.guess_object_field_spec_object(
  value,
  name,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib_row field specification.


Guess the spec for an object list field

Description

Guess the spec for an object list field

Usage

.guess_object_field_spec_object_list(
  value,
  name,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib_df() spec keyed by name.


Guess the field spec for a vector-typed field

Description

Guess the field spec for a vector-typed field

Usage

.guess_object_field_spec_vector(value, name)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

Value

A tib field specification.


Guess the spec for a single field in an object list

Description

Guess the spec for a single field in an object list

Usage

.guess_object_list_field_spec(
  value,
  name,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib field spec.


Guess the spec for a list field without list simplification

Description

Guess the spec for a list field without list simplification

Usage

.guess_object_list_field_spec_dont_simplify(
  value,
  name,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib field spec.


Guess a vector spec from a flat list of field values

Description

Guess a vector spec from a flat list of field values

Usage

.guess_object_list_field_spec_flat_to_vector(value_flat, name, ptype_result)

Arguments

value_flat

(list) The flattened values of a list field.

name

(character(1)) The name of the field.

ptype_result

(list) The result of .get_ptype_common() applied to value_flat.

Value

A tib_vector() spec.


Guess a row spec from an object list field

Description

Guess a row spec from an object list field

Usage

.guess_object_list_field_spec_object_list_row(
  value,
  name,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib_row() spec.


Guess the spec for a vector-typed field in an object list

Description

Guess the spec for a vector-typed field in an object list

Usage

.guess_object_list_field_spec_vector(
  value,
  name,
  ptype,
  had_empty_lists,
  local_env
)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

ptype

(vector(0)) A prototype of the desired output type of the field.

had_empty_lists

(logical(1) or NULL) Whether empty lists were dropped when computing the common ptype.

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib_scalar() or tib_vector() spec.


Guess field specs for an object list

Description

Guess field specs for an object list

Usage

.guess_object_list_spec(
  object_list,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

object_list

(list) A list of named lists (objects) whose fields are to be guessed.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A named list of tib field specs.


Guess whether a list field can be simplified to a vector spec

Description

Guess whether a list field can be simplified to a vector spec

Usage

.guess_vector_input_form(value, name)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

Value

A list with:


Build a tib spec for a field-scalar input form

Description

Build a tib spec for a field-scalar input form

Usage

.guess_vector_input_form_field_scalar(value, name, ptype)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

ptype

(vector(0)) A prototype of the desired output type of the field.

Value

A list with can_simplify = TRUE and tib_spec, a tib_vector field specification.


Guess input form for a list field whose common ptype is NULL

Description

Guess input form for a list field whose common ptype is NULL

Usage

.guess_vector_input_form_null(value, name)

Arguments

value

(list) An object list whose fields will be guessed.

name

(character(1)) The name of the field.

Value

A list with:


Apply column-to-spec conversion across a data frame

Description

Apply column-to-spec conversion across a data frame

Usage

.imap_col_to_spec(col_list, empty_list_unspecified, local_env)

Arguments

col_list

(list) A named list of columns, typically a data frame.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A named list of tib field specifications.


Map .guess_object_field_spec over a named list

Description

Map .guess_object_field_spec over a named list

Usage

.imap_guess_object_field_spec(
  x,
  empty_list_unspecified,
  simplify_list,
  local_env
)

Arguments

x

(any) The object to check.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A named list of tib field specifications, one per element of x.


Is every element of a field scalar?

Description

Is every element of a field scalar?

Usage

.is_field_scalar(value)

Arguments

value

(list) An object list whose fields will be guessed.

Value

TRUE if every element has size 1 or is NULL, FALSE otherwise.


Is x a list of NULLs?

Description

Is x a list of NULLs?

Usage

.is_list_of_null(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if every element of x is NULL, FALSE otherwise.


Is x a list of object lists?

Description

Is x a list of object lists?

Usage

.is_list_of_object_lists(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if every non-NULL element of x is a list of objects, FALSE otherwise.


Is x an object?

Description

Is x an object?

Usage

.is_object(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is an object (a fully named list with unique names), FALSE otherwise.


Is x a list of objects?

Description

Is x a list of objects?

Usage

.is_object_list(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a list of objects, FALSE otherwise.


Check if object is a tib collector

Description

Check if object is a tib collector

Usage

.is_tib(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a tib_collector.


Check if a tib field has a canonical name

Description

Check if a tib field has a canonical name

Usage

.is_tib_name_canonical(field, name)

Arguments

field

(list) A tib field.

name

(character(1)) The name to check against the field's key.

Value

TRUE if the field's key is a single string that matches name, FALSE otherwise.


Check if object is a tib row

Description

Check if object is a tib row

Usage

.is_tib_row(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a tib_row.


Check if object is a tib scalar

Description

Check if object is a tib scalar

Usage

.is_tib_scalar(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a tib_scalar.


Check if object is a tib unspecified

Description

Check if object is a tib unspecified

Usage

.is_tib_unspecified(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a tib_unspecified.


Check if object is a tib variant

Description

Check if object is a tib variant

Usage

.is_tib_variant(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a tib_variant.


Check if object is a tib vector

Description

Check if object is a tib vector

Usage

.is_tib_vector(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a tib_vector.


Check if object is a tibblify specification

Description

Check if object is a tibblify specification

Usage

.is_tspec(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if x is a tspec object.


Is the object unspecified?

Description

Is the object unspecified?

Usage

.is_unspecified(x)

Arguments

x

(any) The object to check.

Value

TRUE if the object has class "vctrs_unspecified", FALSE otherwise.


Check whether input is an http(s) URL string

Description

Check whether input is an http(s) URL string

Usage

.is_url_string(x, arg = caller_arg(x), call = caller_env())

Arguments

x

(any) The object to check.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

(logical(1)) TRUE for scalar strings starting with ⁠http://⁠ or ⁠https://⁠, FALSE otherwise.


Is the object a vector?

Description

Is the object a vector?

Usage

.is_vec(x)

Arguments

x

(any) The object to check.

Value

TRUE if the object is a non-list vector, FALSE otherwise.


Convert a logical vector to cli bullet symbols

Description

Convert a logical vector to cli bullet symbols

Usage

.lgl_to_bullet(x)

Arguments

x

(logical) A logical vector where TRUE maps to a check mark bullet and FALSE to a cross bullet.

Value

(character) A character vector of cli bullet names ("v" or "x") the same length as x.


Convert a list column to a tib field specification

Description

Inspects the elements of col to determine whether they share a common ptype and dispatches to the appropriate spec builder.

Usage

.list_col_to_spec(col, name, empty_list_unspecified, local_env)

Arguments

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

name

(character(1)) The name of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A tib field specification.


For each element, is it a list of NULLs?

Description

For each element, is it a list of NULLs?

Usage

.list_is_list_of_null(x)

Arguments

x

(any) The object to check.

Value

(logical) A logical vector the same length as x, where each element is TRUE if the corresponding element of x is itself a list of NULLs.


Build field specs from a list_of df column

Description

Build field specs from a list_of df column

Usage

.list_of_col_to_spec_df(col, ptype, empty_list_unspecified, local_env)

Arguments

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

ptype

(vector(0)) A prototype of the desired output type of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A named list of tib field specifications.


Format location names and types

Description

Format location names and types

Usage

.loc_name_helper(locs, types)

Arguments

locs

(integer) Locations of the elements.

types

(character) Types of those elements.

Value

(character) Dot-prefixed location names and types.


Mark that the empty list argument was used

Description

Mark that the empty list argument was used

Usage

.mark_empty_list_argument(used_empty_list_arg, local_env)

Arguments

used_empty_list_arg

(logical(1)) Whether any empty lists were dropped during ptype detection due to empty_list_unspecified.

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

Called for its side effect of setting local_env$empty_list_used to TRUE when used_empty_list_arg is TRUE.


Potentially inform users about unspecified fields

Description

Potentially inform users about unspecified fields

Usage

.maybe_inform_unspecified(spec, inform_unspecified, call = caller_env())

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

inform_unspecified

(logical(1)) Inform about fields whose type could not be determined?

call

(environment) The environment to use for error messages.

Value

The spec object.


Collapse expressions with padding and optional multi-line formatting

Description

Collapse expressions with padding and optional multi-line formatting

Usage

.name_exprs(exprs, names, show_name)

Arguments

exprs

(list) Expressions to collapse.

names

(character) Names corresponding to the expressions.

show_name

(logical) A vector indicating whether each name should be shown.

Value

A character vector of the expressions with names prepended where show_name is TRUE. Non-syntactic names are backticked. If show_name is FALSE, the expressions are returned without names.


Calculate the number of characters in a field's name part

Description

Calculate the number of characters in a field's name part

Usage

.nchar_field_names(fields)

Arguments

fields

(list or NULL) Fields to format.

Value

An integer vector of the number of characters in the name part of each field, including the "=" separator and a trailing comma.


Main implementation of tree nesting

Description

Main implementation of tree nesting

Usage

.nest_tree_impl(
  x,
  id_col,
  parent_col,
  children_to,
  id_col_name,
  call = caller_env()
)

Arguments

x

(any) The object to check.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

children_to

(character(1)) The column name in which to store the children.

id_col_name

(character(1)) The name of the column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

A nested data frame with children column and parent column removed.


Compute tree level for each element based on id and parent relationships

Description

Compute tree level for each element based on id and parent relationships

Usage

.nest_tree_lvl(ids, parent_ids, id_col_name, call = caller_env())

Arguments

ids

(character or integer) The potential child ids to compare against.

parent_ids

(character or integer) The parent ids to check.

id_col_name

(character(1)) The name of the column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

A list with lvls (integer vector of levels) and max_lvl (maximum level).


Build field specs from a non-list_of df column

Description

Build field specs from a non-list_of df column

Usage

.non_list_of_col_to_spec_df(col, ptype, empty_list_unspecified, local_env)

Arguments

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

ptype

(vector(0)) A prototype of the desired output type of the field.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

A named list of tib field specifications with required set.


Resolve child_col to a column name string

Description

Resolve child_col to a column name string

Usage

.normalize_child_col_name(child_col, x, id_col, call = caller_env())

Arguments

child_col

(character(1), integer(1), or symbol) The column that contains the children of an observation. This column must be a list where each element is either NULL or a data frame with the same columns as x.

x

(data.frame) The data frame to unnest.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

child_col resolved to a character(1) column name.


Normalize and check the id column

Description

Normalize and check the id column

Usage

.normalize_id_col(id_col, x, call = caller_env())

Arguments

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

x

(any) The object to check.

call

(environment) The environment to use for error messages.

Value

The integer index of the id column.


Resolve id_col to a column name string

Description

Resolve id_col to a column name string

Usage

.normalize_id_col_name(id_col, x, call = caller_env())

Arguments

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

x

(data.frame) The data frame to unnest.

call

(environment) The environment to use for error messages.

Value

id_col resolved to a character(1) column name.


Normalize and check the parent column

Description

Normalize and check the parent column

Usage

.normalize_parent_col(parent_col, x, id_col, id_col_name, call = caller_env())

Arguments

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

x

(any) The object to check.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

id_col_name

(character(1)) The name of the column that uniquely identifies each observation.

call

(environment) The environment to use for error messages.

Value

The integer index of the parent column.


Resolve ⁠$ref⁠ references in an OpenAPI schema object

Description

Resolve ⁠$ref⁠ references in an OpenAPI schema object

Usage

.openapi_resolve_reference(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

(list) The schema with all ⁠$ref⁠ references resolved.


Pad a character vector with a specified number of spaces

Description

Pad a character vector with a specified number of spaces

Usage

.pad(x, n)

Arguments

x

(character) A vector to pad.

n

(integer) The number of spaces to use for padding.

Value

A character vector with each element of x prepended with n spaces. If an element of x contains newlines, each line will be prepended with n spaces.


Parse a named list of header objects from an OpenAPI spec

Description

Parse a named list of header objects from an OpenAPI spec

Usage

.parse_header_objects(header_objects, openapi_spec)

Arguments

header_objects

(list) A named list of header objects from an OpenAPI spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

(tbl_df) A tibble of parsed header objects.


Parse a named list of media type objects from an OpenAPI spec

Description

Parse a named list of media type objects from an OpenAPI spec

Usage

.parse_media_type_objects(media_type_objects, openapi_spec)

Arguments

media_type_objects

(list) A named list of media type objects from an OpenAPI spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

(tbl_df) A tibble with media_type and spec columns.


Parse an operation object from an OpenAPI spec

Description

Parse an operation object from an OpenAPI spec

Usage

.parse_operation_object(operation_object, openapi_spec)

Arguments

operation_object

(list) An operation object from an OpenAPI spec, as defined in the Operation Object.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A one-row tibble describing the operation.


Parse a list of parameter objects from an OpenAPI spec

Description

Parse a list of parameter objects from an OpenAPI spec

Usage

.parse_parameters(parameters, openapi_spec)

Arguments

parameters

(list or NULL) A list of parameter objects from an OpenAPI spec, as defined in the Parameter Object.

openapi_spec

(list) A parsed OpenAPI specification.

Value

(tbl_df or NULL) A tibble of parsed parameters, or NULL if parameters is NULL.


Parse a path item object from an OpenAPI spec

Description

Parse a path item object from an OpenAPI spec

Usage

.parse_path_item_object(path_item_object, openapi_spec)

Arguments

path_item_object

(list) A path item object from an OpenAPI spec, as defined in the Path Item Object.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tibble of parsed operations with a global_parameters column.


Parse all path item objects from an OpenAPI spec

Description

Parse all path item objects from an OpenAPI spec

Usage

.parse_path_item_objects(openapi_spec)

Arguments

openapi_spec

(list) A parsed OpenAPI specification.

Value

A named list of tibbles, one per path, containing parsed operations.


Parse a request body object from an OpenAPI spec

Description

Parse a request body object from an OpenAPI spec

Usage

.parse_request_body(request_body, openapi_spec)

Arguments

request_body

(list or NULL) A request body object from an OpenAPI spec, as defined in the Request Body Object.

openapi_spec

(list) A parsed OpenAPI specification.

Value

(tspec_row or NULL) A parsed request body row spec, or NULL if request_body is NULL.


Parse a single response object from an OpenAPI spec

Description

Parse a single response object from an OpenAPI spec

Usage

.parse_response_object(response_object, openapi_spec)

Arguments

response_object

(list) A response object from an OpenAPI spec, as defined in the Response Object.

openapi_spec

(list) A parsed OpenAPI specification.

Value

(tbl_df) A one-row tibble describing the response.


Parse a responses object from an OpenAPI spec

Description

Parse a responses object from an OpenAPI spec

Usage

.parse_responses_object(responses_object, openapi_spec)

Arguments

responses_object

(list) A responses object from an OpenAPI spec, mapping status codes to response objects, as defined in the Responses Object.

openapi_spec

(list) A parsed OpenAPI specification.

Value

(tbl_df) A tibble of parsed response objects with a status_code column.


Parse an OpenAPI schema object into a tib field spec

Description

Parse an OpenAPI schema object into a tib field spec

Usage

.parse_schema(schema, name, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

name

(character(1)) The name of the field.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tib field spec corresponding to the schema type.


Pad and collapse a character vector across multiple lines

Description

Pad and collapse a character vector across multiple lines

Usage

.paste_multiline(x)

Arguments

x

(character) A vector to pad and collapse.

Value

A single string with the elements of x padded and collapsed across multiple lines, with a leading newline and a trailing comma on each line.


Convert a path object to a printable string

Description

Convert a path object to a printable string

Usage

.path_to_string(path)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

Value

(character(1)) A string path such as "x$a[[1]]".


Prepare a complex field

Description

Prepare a complex field

Usage

.prep_complex_field(key, spec_fields)

Arguments

key

(character(1)) The key of the field.

spec_fields

(list) Fields from spec$fields (or a subset thereof).

Value

A prepared field specification.


Prepare nested keys in a tibblify specification

Description

Prepare nested keys in a tibblify specification

Usage

.prep_nested_keys(spec_fields, coll_locations)

Arguments

spec_fields

(list) Fields from spec$fields (or a subset thereof).

coll_locations

(integer) A numeric vector of locations.

Value

A list with prepared fields, keys, and locations.


Prepare a simple field

Description

Prepare a simple field

Usage

.prep_simple_field(x)

Arguments

x

(tib_collector) A field specification.

Value

A prepared field specification.


Flatten, validate, and auto-name field specifications

Description

Flatten, validate, and auto-name field specifications

Usage

.prep_spec_fields(.fields, .error_call)

Arguments

.fields

(list) A list of field specifications, typically created by ⁠tib_*()⁠.

.error_call

(environment) The environment to use for error messages.

Value

A named list of validated field specifications.


Prepare the fill value for a vector field

Description

Prepare the fill value for a vector field

Usage

.prep_tib_fill(fill, names_to, col_names)

Arguments

fill

(vector) The fill value.

names_to

(character(1)) Name of the names column.

col_names

(character) Column names.

Value

The existing fill value, or a tibble representing the fill.


Prepare the ptype list for a vector field

Description

Prepare the ptype list for a vector field

Usage

.prep_tib_list_of_ptype(ptype, names_to, col_names)

Arguments

ptype

(vector(0)) The target ptype.

names_to

(character(1)) Name of the names column.

col_names

(character) Column names.

Value

A tibble representing the ptype.


Prepare a scalar field

Description

Prepare a scalar field

Usage

.prep_tib_scalar(x)

Arguments

x

(tib_collector) A field specification.

Value

A prepared scalar field specification.


Prepare a vector field

Description

Prepare a vector field

Usage

.prep_tib_vector(x)

Arguments

x

(tib_collector) A field specification.

Value

A prepared vector field specification.


Prepare transform function

Description

Prepare transform function

Usage

.prep_transform(f, .call, arg = ".transform")

Arguments

f

(function or NULL) The function to prepare.

.call

(environment) The environment to use for error messages.

arg

(character(1)) The argument name.

Value

(function or NULL) The prepared function.


Process complex fields (depth > 1)

Description

Process complex fields (depth > 1)

Usage

.process_complex_fields(spec_fields, first_keys)

Arguments

spec_fields

(list) Fields from spec$fields (or a subset thereof).

first_keys

(character) First keys of the complex fields.

Value

A list of prepared fields.


Process simple fields (depth 1)

Description

Process simple fields (depth 1)

Usage

.process_simple_fields(spec_fields)

Arguments

spec_fields

(list) Fields from spec$fields (or a subset thereof).

Value

A list of prepared fields.


Read whether the empty list argument was used

Description

Read whether the empty list argument was used

Usage

.read_empty_list_argument(local_env)

Arguments

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

Value

TRUE if local_env$empty_list_used is TRUE, FALSE otherwise.


Read an OpenAPI schema from a file, connection, or list

Description

Read an OpenAPI schema from a file, connection, or list

Usage

.read_schema(file, arg = caller_arg(file), call = caller_env())

Arguments

file

(character(1)) A path to a file, a connection, or literal data.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

(list) The parsed schema.


Read an OpenAPI spec from a file, connection, or list

Description

Read an OpenAPI spec from a file, connection, or list

Usage

.read_spec(file, arg = caller_arg(file), call = caller_env())

Arguments

file

(character(1)) A path to a file, a connection, or literal data.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

(list) The parsed spec.


Read an OpenAPI spec or schema from a file, connection, or list

Description

Read an OpenAPI spec or schema from a file, connection, or list

Usage

.read_spec_impl(file, arg = caller_arg(file), call = caller_env())

## S3 method for class 'list'
.read_spec_impl(file, ...)

## S3 method for class 'connection'
.read_spec_impl(file, ...)

## S3 method for class 'character'
.read_spec_impl(file, arg = caller_arg(file), call = caller_env())

## Default S3 method:
.read_spec_impl(file, arg = caller_arg(file), call = caller_env())

Arguments

file

(character(1)) A path to a file, a connection, or literal data.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

call

(environment) The environment to use for error messages.

Value

(list) The parsed spec or schema.


Reduce per-level data frames to their combined ptype

Description

Reduce per-level data frames to their combined ptype

Usage

.reduce_ptype(snapshots, call)

Arguments

snapshots

(list) The object returned by .walk_tree_levels().

call

(environment) The environment to use for error messages.

Value

A 0-row data frame representing the combined type of all levels.


Remove the first key from a field

Description

Remove the first key from a field

Usage

.remove_first_key(x)

Arguments

x

(tib_collector) A field specification.

Value

The field specification with the first key removed.


Check whether any nested list element has a ⁠$ref⁠ key

Description

Check whether any nested list element has a ⁠$ref⁠ key

Usage

.schema_has_ref(x)

Arguments

x

(any) The object to check.

Value

(logical(1)) TRUE if any element has a ⁠$ref⁠ key.


Set the tibblify specification attribute

Description

Set the tibblify specification attribute

Usage

.set_spec(x, spec)

Arguments

x

(list) A nested list.

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

Value

The object x with the tib_spec attribute set.


Shared parameters

Description

These parameters are used in multiple functions. They are defined here to make them easier to import and to find.

Arguments

allow_null

(logical(1)) Whether NULL is accepted.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

.call

(environment) The environment to use for error messages.

.children

(character(1)) The name of the field that contains the children.

.children_to

(character(1)) The column name in which to store the children.

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

col_name

(character(1)) The name of the column.

elt

(character or integer) An element of a path.

.elt_transform

(function or NULL) A function to apply to each element before casting to .ptype_inner.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

env

(environment) The environment used to evaluate glue fields in message.

.error_call

(environment) The environment to use for error messages.

expr

(any) An expression to evaluate and return, with indexed errors wrapped.

f_name

(character(1)) The (possibly ANSI-colored) function name.

field_spec

(tib_collector) A tibblify field collector.

file

(character(1)) A path to a file, a connection, or literal data.

.fill

(vector or NULL) Optionally, a value to use if the field does not exist. Note: this value must match the .ptype_inner of the field (the value before any transformation), not the .ptype.

force_names

(logical(1)) Should names be printed even if they can be deduced from the spec?

.format

(character(1) or NULL) Passed to the format argument of as.Date().

header_objects

(list) A named list of header objects from an OpenAPI spec.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

id_col_name

(character(1)) The name of the column that uniquely identifies each observation.

index

(integer(1)) A zero-based location in a path.

inform_unspecified

(logical(1)) Inform about fields whose type could not be determined?

input_form

(character(1)) The input form string used in error messages.

.key

(character) The path of names to the field in the object.

local_env

(environment) A local environment used to track state across recursive calls, such as whether empty lists were encountered.

media_type_object

(list) A single media type object from an OpenAPI spec.

media_type_objects

(list) A named list of media type objects from an OpenAPI spec.

message

(character) A cli message template.

multi_line

(logical(1)) Should the output be formatted across multiple lines? For example, should each element of even a short list be displayed on its own line?

name

(character(1)) The name of the field.

name_spec

(character(1), function, or NULL) Name specification passed to vctrs::list_unchop().

names

(logical(1)) Should names be printed even if they can be deduced from the spec?

nchar_indent

(integer(1)) The number of (additional) characters that will be used to indent the output when multi_line = TRUE. Primarily for internal use when formatting is applied recursively.

openapi_spec

(list) A parsed OpenAPI specification.

operation_object

(list) An operation object from an OpenAPI spec, as defined in the Operation Object.

parameters

(list or NULL) A list of parameter objects from an OpenAPI spec, as defined in the Parameter Object.

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

path

(list) A path object encoded as a depth and a list of path elements.

path_exp

(list) The path of the field used as the reference in size mismatch errors.

path_item_object

(list) A path item object from an OpenAPI spec, as defined in the Path Item Object.

.ptype

(vector(0)) A prototype of the desired output type of the field.

.ptype_inner

(vector(0)) A prototype of the input field.

request_body

(list or NULL) A request body object from an OpenAPI spec, as defined in the Request Body Object.

.required

(logical(1)) Throw an error if the field does not exist?

response_object

(list) A response object from an OpenAPI spec, as defined in the Response Object.

responses_object

(list) A responses object from an OpenAPI spec, mapping status codes to response objects, as defined in the Responses Object.

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

size_act

(integer(1)) The observed size of a field.

size_exp

(integer(1)) The expected size of a field.

spec

(tspec or NULL) A spec object describing the structure of x.

spec_list

(list) A list of specifications.

tib_list

(list) A list of tib fields.

.transform

(function or NULL) A function to apply to the whole vector after casting to .ptype_inner.

value

(list) An object list whose fields will be guessed.

.values_to

(character(1) or NULL) For NULL (the default), the field is converted to a .ptype vector. If a string is provided, the field is converted to a tibble and the values go into the specified column.

width

(integer(1)) The width (in number of characters) of text output to generate.

x

(any) The object to check.

x_arg

(character(1)) The name of the x argument. This name will be mentioned in error messages as the input that is at the origin of a problem.


Shared spec_prep parameters

Description

These parameters are used in multiple .spec_prep()-related functions. They are defined here to make them easier to import and to find. This break-out is for parameters that may differ from other functions that use the same parameter names.

Arguments

coll_locations

(integer) A numeric vector of locations.

field_spec

(tib_collector) A field specification.

fill

(vector) The fill value.

first_keys

(character) First keys of the complex fields.

key

(character(1)) The key of the field.

spec_fields

(list) Fields from spec$fields (or a subset thereof).

x

(tib_collector) A field specification.

ptype

(vector(0)) The target ptype.

names_to

(character(1)) Name of the names column.

col_names

(character) Column names.


Shared tib_spec parameters

Description

These parameters are used in multiple ⁠tib_*()⁠ functions. They are defined here to make them easier to import and to find, and to make sure the deprecated forms get documented identically when these definitions are imported. This break-out is for parameters that differ between ⁠tib_*()⁠ functions and other functions that use the same parameters.

Arguments

.input_form

(character(1)) The structure of the input field. Can be one of:

  • "vector": The field is a vector, e.g. c(1, 2, 3).

  • "scalar_list": The field is a list of scalars, e.g. list(1, 2, 3).

  • "object": The field is a named list of scalars, e.g. list(a = 1, b = 2, c = 3).

.names_to

(character(1) or NULL) What to do with the inner names of the object. Can be one of:

  • NULL: the default. The inner names of the field are not used.

  • A string: Use only if the input form is "object" or "vector", and .values_to is a string. The inner names of the field will populate the specified column in the field's tibble.


Shared (un)nest_tree parameters

Description

These parameters are used in multiple nest_tree() or unnest_tree() helpers. They are defined here to make them easier to import and to find. This break-out is for parameters that differ between ⁠(un)nest_tree()⁠ helpers and other functions that might use the same parameters.

Arguments

col

(character, integer, or symbol) Defused R code describing a selection according to the tidyselect syntax.

col_arg

(character(1)) The name of the col argument, used for error messages.

ids

(character or integer) The potential child ids to compare against.

parent_ids

(character or integer) The parent ids to check.


Determine whether to print names for tibblifying

Description

Determine whether to print names for tibblifying

Usage

.should_force_names()

Value

A logical value indicating whether to print names for tibblifying, based on the tibblify.print_names option.


Sort specification by the first key

Description

Sort specification by the first key

Usage

.sort_spec_by_first_key(spec_fields, coll_locations)

Arguments

spec_fields

(list) Fields from spec$fields (or a subset thereof).

coll_locations

(integer) A numeric vector of locations.

Value

A list with sorted components.


Auto-name fields based on their key attribute

Description

Auto-name fields based on their key attribute

Usage

.spec_auto_name_fields(.fields, .error_call)

Arguments

.fields

(list) A list of field specifications, typically created by ⁠tib_*()⁠.

.error_call

(environment) The environment to use for error messages.

Value

A named list of field specifications.


Inform about or error for unspecified fields

Description

Inform about or error for unspecified fields

Usage

.spec_inform_unspecified(spec, unspecified = "inform", call = caller_env())

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

unspecified

(character(1)) What to do with tib_unspecified() fields. Can be one of

  • "error": Throw an error.

  • "inform": Inform the user then parse as with tib_variant().

  • "drop": Do not parse these fields.

  • "list": Parse unspecified fields into lists as with tib_variant().

call

(environment) The environment to use for error messages.

Value

The original spec, invisibly.


Prepare a tibblify specification for tibblification

Description

Prepare a tibblify specification for tibblification

Usage

.spec_prep(spec)

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

Value

A prepared tibblify specification.


Prepare a non-recursive tibblify specification

Description

Prepare a non-recursive tibblify specification

Usage

.spec_prep_nonrecursive(spec)

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

Value

A prepared tibblify specification.


Prepare a recursive tibblify specification

Description

Prepare a recursive tibblify specification

Usage

.spec_prep_recursive(spec)

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

Value

A prepared tibblify specification.


Prepare unspecified fields

Description

Prepare unspecified fields

Usage

.spec_prep_unspecified(spec, unspecified, call = caller_env())

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

unspecified

(character(1)) What to do with tib_unspecified() fields. Can be one of

  • "error": Throw an error.

  • "inform": Inform the user then parse as with tib_variant().

  • "drop": Do not parse these fields.

  • "list": Parse unspecified fields into lists as with tib_variant().

call

(environment) The environment to use for error messages.

Value

A prepared tibblify specification.


Replace unspecified fields in the specification

Description

Replace unspecified fields in the specification

Usage

.spec_replace_unspecified(spec, unspecified)

Arguments

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

unspecified

(character(1)) What to do with tib_unspecified() fields. Can be one of

  • "error": Throw an error.

  • "inform": Inform the user then parse as with tib_variant().

  • "drop": Do not parse these fields.

  • "list": Parse unspecified fields into lists as with tib_variant().

Value

A modified tibblify specification.


Replace unspecified fields in the specification

Description

Replace unspecified fields in the specification

Usage

.spec_replace_unspecified_impl(spec_fields, unspecified)

Arguments

spec_fields

(list) Fields from spec$fields (or a subset thereof).

unspecified

(character(1)) What to do with tib_unspecified() fields. Can be one of

  • "error": Throw an error.

  • "inform": Inform the user then parse as with tib_variant().

  • "drop": Do not parse these fields.

  • "list": Parse unspecified fields into lists as with tib_variant().

Value

A modified list of tib_collector objects.


Replace tib_unspecified fields in the specification

Description

Replace tib_unspecified fields in the specification

Usage

.spec_replace_unspecified_type(field_spec, unspecified)

Arguments

field_spec

(tib_collector) A field specification.

unspecified

(character(1)) What to do with tib_unspecified() fields. Can be one of

  • "error": Throw an error.

  • "inform": Inform the user then parse as with tib_variant().

  • "drop": Do not parse these fields.

  • "list": Parse unspecified fields into lists as with tib_variant().

Value

A modified tib_collector.


Stabilize names_to argument

Description

Stabilize names_to argument

Usage

.stabilize_names_to(.names_to, .values_to, .input_form, .call)

Arguments

.names_to

(character(1) or NULL) What to do with the inner names of the object. Can be one of:

  • NULL: the default. The inner names of the field are not used.

  • A string: Use only if the input form is "object" or "vector", and .values_to is a string. The inner names of the field will populate the specified column in the field's tibble.

.values_to

(character(1) or NULL) For NULL (the default), the field is converted to a .ptype vector. If a string is provided, the field is converted to a tibble and the values go into the specified column.

.input_form

(character(1)) The structure of the input field. Can be one of:

  • "vector": The field is a vector, e.g. c(1, 2, 3).

  • "scalar_list": The field is a list of scalars, e.g. list(1, 2, 3).

  • "object": The field is a named list of scalars, e.g. list(a = 1, b = 2, c = 3).

.call

(environment) The environment to use for error messages.

Value

(character(1) or NULL) Validated .names_to.


Check which fields to unpack

Description

Check which fields to unpack

Usage

.stabilize_unpack_cols(fields, spec, .call = caller_env())

Arguments

fields

(character or NULL) The fields to unpack.

spec

(tspec) A tibblify specification.

.call

(environment) The environment to use for error messages.

Value

(character) The names of the fields to unpack.


Stabilize values_to argument

Description

Stabilize values_to argument

Usage

.stabilize_values_to(.values_to, .call)

Arguments

.values_to

(character(1) or NULL) For NULL (the default), the field is converted to a .ptype vector. If a string is provided, the field is converted to a tibble and the values go into the specified column.

.call

(environment) The environment to use for error messages.

Value

(character(1) or NULL) Validated .values_to.


Error for NULL in colmajor fields

Description

Error for NULL in colmajor fields

Usage

.stop_colmajor_null(path)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for inconsistent colmajor field sizes

Description

Error for inconsistent colmajor field sizes

Usage

.stop_colmajor_wrong_size_element(path, size_act, path_exp, size_exp)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

size_act

(integer(1)) The observed size of a field.

path_exp

(list) The path of the field used as the reference in size mismatch errors.

size_exp

(integer(1)) The expected size of a field.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for duplicate names

Description

Error for duplicate names

Usage

.stop_duplicate_name(path, name)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

name

(character(1)) The name of the field.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for empty names

Description

Error for empty names

Usage

.stop_empty_name(path, index)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

index

(integer(1)) A zero-based location in a path.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for unnamed object

Description

Error for unnamed object

Usage

.stop_names_is_null(path)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for non-list element

Description

Error for non-list element

Usage

.stop_non_list_element(path, x)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

x

(any) The object to check.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for unnamed object vector

Description

Error for unnamed object vector

Usage

.stop_object_vector_names_is_null(path)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for missing required field

Description

Error for missing required field

Usage

.stop_required(path)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for missing required colmajor field

Description

Error for missing required colmajor field

Usage

.stop_required_colmajor(path)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for non-scalar field

Description

Error for non-scalar field

Usage

.stop_scalar(path, size_act)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

size_act

(integer(1)) The observed size of a field.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for non-list vector element

Description

Error for non-list vector element

Usage

.stop_vector_non_list_element(path, input_form, x)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

input_form

(character(1)) The input form string used in error messages.

x

(any) The object to check.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Error for wrong-sized vector element

Description

Error for wrong-sized vector element

Usage

.stop_vector_wrong_size_element(path, input_form, x)

Arguments

path

(list) A path object encoded as a depth and a list of path elements.

input_form

(character(1)) The input form string used in error messages.

x

(any) The object to check.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Create a tib collector

Description

Create a tib collector

Usage

.tib_collector(
  .key,
  .type,
  ...,
  .required = TRUE,
  .class = NULL,
  .transform = NULL,
  .elt_transform = NULL,
  .call = caller_env()
)

Arguments

.key

(character) The path of names to the field in the object.

.type

(character(1)) The type of the collector.

.required

(logical(1)) Throw an error if the field does not exist?

.class

(character or NULL) Additional classes for the collector.

.transform

(function or NULL) A function to apply to the whole vector after casting to .ptype_inner.

.elt_transform

(function or NULL) A function to apply to each element before casting to .ptype_inner.

.call

(environment) The environment to use for error messages.

Value

(tib_collector) A tibblify collector.


Combine a list of tib fields

Description

Combine a list of tib fields

Usage

.tib_combine(tib_list, name, .call)

Arguments

tib_list

(list) A list of tib fields.

name

(character(1)) The name of the field.

.call

(environment) The environment to use for error messages.

Value

(tib_collector) A combined tibblify field collector.


Combine dataframe tib fields

Description

Combine dataframe tib fields

Usage

.tib_combine_df(tib_list, type, key, required, .call)

Arguments

tib_list

(list) A list of tib fields.

type

(character(1)) The target tib type ("row" or "df").

key

(character(1)) The key of the field.

required

(logical(1)) Whether the field is required.

.call

(environment) The environment to use for error messages.

Value

(tib_row or tib_df) A tibblify dataframe field collector.


Combine fill values from a list of tibs

Description

Combine fill values from a list of tibs

Usage

.tib_combine_fill(tib_list, type, ptype, .call)

Arguments

tib_list

(list) A list of tib fields.

type

(character(1)) The target tib type (scalar, vector, etc.).

ptype

(vector(0)) The target ptype.

.call

(environment) The environment to use for error messages.

Value

(vector) The combined fill value.


Combine input forms from a list of tibs

Description

Combine input forms from a list of tibs

Usage

.tib_combine_input_form(tib_list, .call)

Arguments

tib_list

(list) A list of tib fields.

.call

(environment) The environment to use for error messages.

Value

(character(1)) The combined input form.


Combine keys from a list of tibs

Description

Combine keys from a list of tibs

Usage

.tib_combine_key(tib_list, name, .call)

Arguments

tib_list

(list) A list of tib fields.

name

(character(1)) The name of the field.

.call

(environment) The environment to use for error messages.

Value

(character(1)) The combined key.


Combine names_col value from a list of tibs

Description

Combine names_col value from a list of tibs

Usage

.tib_combine_names_col(tib_list, .call)

Arguments

tib_list

(list) A list of tib fields.

.call

(environment) The environment to use for error messages.

Value

(character(1) or NULL) The combined names column.


Combine ptypes from a list of tibs

Description

Combine ptypes from a list of tibs

Usage

.tib_combine_ptype(tib_list, .call)

Arguments

tib_list

(list) A list of tib fields.

.call

(environment) The environment to use for error messages.

Value

(vector(0)) The combined ptype.


Combine required status from a list of tibs

Description

Combine required status from a list of tibs

Usage

.tib_combine_required(tib_list)

Arguments

tib_list

(list) A list of tib fields.

Value

(logical(1)) The combined required status.


Combine various specified tib field types

Description

Combine various specified tib field types

Usage

.tib_combine_specified(tib_list, type, key, required, .call)

Arguments

tib_list

(list) A list of tib fields.

type

(character(1)) The target tib type ("variant", "scalar", or "vector").

key

(character(1)) The key of the field.

required

(logical(1)) Whether the field is required.

.call

(environment) The environment to use for error messages.

Value

(tib_variant, tib_scalar, or tib_vector) A tibblify field collector.


Combine transform functions from a list of tibs

Description

Combine transform functions from a list of tibs

Usage

.tib_combine_transform(tib_list, .call)

Arguments

tib_list

(list) A list of tib fields.

.call

(environment) The environment to use for error messages.

Value

(function or NULL) The combined transform function.


Combine types from a list of tibs

Description

Combine types from a list of tibs

Usage

.tib_combine_type(tib_list, .call)

Arguments

tib_list

(list) A list of tib fields.

.call

(environment) The environment to use for error messages.

Value

(character(1)) The combined tib type.


Combine vector tib fields

Description

Combine vector tib fields

Usage

.tib_combine_vector(tib_list, key, ptype, required, fill, transform, .call)

Arguments

tib_list

(list) A list of tib fields.

key

(character(1)) The key of the field.

ptype

(vector(0)) The target ptype.

required

(logical(1)) Whether the field is required.

fill

(vector) The fill value.

transform

(function or NULL) The transform function.

.call

(environment) The environment to use for error messages.

Value

(tib_vector) A tibblify vector field collector.


Combine allOf sub-schemas into a tib field

Description

Combine allOf sub-schemas into a tib field

Usage

.tib_from_all_of(schema, name, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

name

(character(1)) The name of the field.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A combined tib field spec.


Combine anyOf sub-schemas into a tib field

Description

Combine anyOf sub-schemas into a tib field

Usage

.tib_from_any_of(schema, name, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

name

(character(1)) The name of the field.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A combined tib field spec, or tib_variant() if schemas are incompatible.


Combine oneOf sub-schemas into a tib field

Description

Combine oneOf sub-schemas into a tib field

Usage

.tib_from_one_of(schema, name, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

name

(character(1)) The name of the field.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A combined tib field spec, or tib_variant() if schemas are incompatible.


Parse an array-type OpenAPI schema and create a tib field

Description

Parse an array-type OpenAPI schema and create a tib field

Usage

.tib_from_schema_array(schema, name, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

name

(character(1)) The name of the field.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tib field spec for the array, which may be a vector, data frame, or variant field depending on the array items schema.


Parse an object-type OpenAPI schema and create a tib field

Description

Parse an object-type OpenAPI schema and create a tib field

Usage

.tib_from_schema_object(schema, name, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

name

(character(1)) The name of the field.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tib_row() field spec with fields extracted from schema properties.


Parse an OpenAPI schema type and create a tib field

Description

Parse an OpenAPI schema type and create a tib field

Usage

.tib_from_schema_type(schema, name, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

name

(character(1)) The name of the field.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tib field spec corresponding to the schema type.


Get the ptype of an object

Description

Get the ptype of an object

Usage

.tib_ptype(x)

Arguments

x

(any) The object to check.

Value

The ptype of x, with POSIXlt coerced to POSIXct.


Implementation of tib_scalar

Description

Implementation of tib_scalar

Usage

.tib_scalar_impl(
  .key,
  .ptype,
  ...,
  .required = TRUE,
  .fill = vctrs::vec_init(.ptype_inner),
  .ptype_inner = .ptype,
  .transform = NULL,
  .class = NULL,
  .call = caller_env()
)

Arguments

.key

(character) The path of names to the field in the object.

.ptype

(vector(0)) A prototype of the desired output type of the field.

.required

(logical(1)) Throw an error if the field does not exist?

.fill

(vector or NULL) Optionally, a value to use if the field does not exist. Note: this value must match the .ptype_inner of the field (the value before any transformation), not the .ptype.

.ptype_inner

(vector(0)) A prototype of the input field.

.transform

(function or NULL) A function to apply to the whole vector after casting to .ptype_inner.

.class

(character or NULL) Additional classes for the collector.

.call

(environment) The environment to use for error messages.

Value

(tib_scalar) A tibblify scalar collector.


Create a scalar or vector tib spec

Description

Create a scalar or vector tib spec

Usage

.tib_scalar_or_vector_spec(name, ptype, is_scalar)

Arguments

name

(character(1)) The name of the field.

ptype

(vector(0)) A prototype of the desired output type of the field.

is_scalar

(logical(1)) If TRUE, return a tib_scalar() spec, otherwise a tib_vector() spec.

Value

A tib_scalar() or tib_vector() spec.


Determine the tib type of an object

Description

Determine the tib type of an object

Usage

.tib_type_of(x, name, other)

Arguments

x

(any) The object to check.

name

(character(1)) The name of the field.

other

(logical(1)) If TRUE, return "other" for unrecognized types rather than throwing an error.

Value

One of "df", "list", "vector", or "other".


Implementation of tib_vector

Description

Implementation of tib_vector

Usage

.tib_vector_impl(
  .key,
  .ptype,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = .ptype,
  .transform = NULL,
  .elt_transform = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  .class = NULL,
  .call = caller_env()
)

Arguments

.key

(character) The path of names to the field in the object.

.ptype

(vector(0)) A prototype of the desired output type of the field.

.required

(logical(1)) Throw an error if the field does not exist?

.fill

(vector or NULL) Optionally, a value to use if the field does not exist. Note: this value must match the .ptype_inner of the field (the value before any transformation), not the .ptype.

.ptype_inner

(vector(0)) A prototype of the input field.

.transform

(function or NULL) A function to apply to the whole vector after casting to .ptype_inner.

.elt_transform

(function or NULL) A function to apply to each element before casting to .ptype_inner.

.input_form

(character(1)) The structure of the input field. Can be one of:

  • "vector": The field is a vector, e.g. c(1, 2, 3).

  • "scalar_list": The field is a list of scalars, e.g. list(1, 2, 3).

  • "object": The field is a named list of scalars, e.g. list(a = 1, b = 2, c = 3).

.values_to

(character(1) or NULL) For NULL (the default), the field is converted to a .ptype vector. If a string is provided, the field is converted to a tibble and the values go into the specified column.

.names_to

(character(1) or NULL) What to do with the inner names of the object. Can be one of:

  • NULL: the default. The inner names of the field are not used.

  • A string: Use only if the input form is "object" or "vector", and .values_to is a string. The inner names of the field will populate the specified column in the field's tibble.

.class

(character or NULL) Additional classes for the collector.

.call

(environment) The environment to use for error messages.

Value

(tib_vector) A tibblify vector collector.


Determine the vector input form of a value

Description

Determine the vector input form of a value

Usage

.tib_vector_input_form(value)

Arguments

value

(list) An object list whose fields will be guessed.

Value

"object" if value is named, "scalar_list" otherwise.


Throw a tibblify internal error

Description

Throw a tibblify internal error

Usage

.tibblify_abort(..., .envir = caller_env())

Arguments

...

Arguments passed to cli::cli_abort().

.envir

(environment) The environment used to evaluate cli fields.

Value

NULL (invisibly). Called for its side effect of throwing an error.


Tibblify implementation

Description

Tibblify implementation

Usage

.tibblify_impl(x, spec, path)

Arguments

x

(list) A nested list.

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

path

(list) The current path in the data structure.

Value

Either a tibble or a list, depending on the specification.


Get the width for tibblifying

Description

Get the width for tibblifying

Usage

.tibblify_width(width = NULL)

Arguments

width

(integer(1)) The width (in number of characters) of text output to generate.

Value

The width to use for tibblifying, either the provided width or the value of the width option if width is NULL.


Tibblify implementation with error handling

Description

Tibblify implementation with error handling

Usage

.try_tibblify_impl(x, spec, call = caller_env())

Arguments

x

(list) A nested list.

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

call

(environment) The environment to use for error messages.

Value

Either a tibble or a list, depending on the specification.


Create a tibblify specification object

Description

Create a tibblify specification object

Usage

.tspec(
  .fields,
  .type,
  ...,
  .vector_allows_empty_list = FALSE,
  .error_call = caller_env()
)

Arguments

.fields

(list) A list of field specifications, typically created by ⁠tib_*()⁠.

.type

(character(1)) The type of specification being created ("df", "object", "row", or "recursive").

...

Additional specification attributes passed to rlang::list2().

.error_call

(environment) The environment to use for error messages.

Value

A tspec object with class ⁠tspec_<type>⁠ and tspec.


Combine fields from a list of specs

Description

Combine fields from a list of specs

Usage

.tspec_combine_field_list(spec_list, .call)

Arguments

spec_list

(list) A list of specifications.

.call

(environment) The environment to use for error messages.

Value

(list) A list of combined fields generated by .tib_combine().


Combine allOf sub-schemas into a tspec

Description

Combine allOf sub-schemas into a tspec

Usage

.tspec_from_all_of(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tspec_combine(), or NULL if schema$allOf is empty.


Combine oneOf sub-schemas into a tspec

Description

Combine oneOf sub-schemas into a tspec

Usage

.tspec_from_one_of(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tspec_combine(), or tib_variant("dummy") if schemas are incompatible, or NULL if schema$oneOf is empty.


Convert an OpenAPI schema to a tibblify tspec

Description

Convert an OpenAPI schema to a tibblify tspec

Usage

.tspec_from_schema(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tibblify spec (tspec_row(), tspec_df(), or a tib field).


Convert an array-type schema to a tibblify data frame spec

Description

Convert an array-type schema to a tibblify data frame spec

Usage

.tspec_from_schema_array(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tspec_df() spec with fields extracted from the array items schema properties.


Convert an object-type schema to a tibblify row spec

Description

Convert an object-type schema to a tibblify row spec

Usage

.tspec_from_schema_object(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tspec_row() spec with fields extracted from schema properties.


Choose and apply a tspec_from_schema_type function

Description

Choose and apply a tspec_from_schema_type function

Usage

.tspec_from_schema_type(schema, openapi_spec)

Arguments

schema

(list) A JSON schema object, as defined in the Schema Object, typically from openapi_spec$components$schemas or inline within the spec.

openapi_spec

(list) A parsed OpenAPI specification.

Value

A tibblify spec (tspec_row(), tspec_df(), or a tib field).


Unclass and unchop a list of child data frames

Description

Unclass and unchop a list of child data frames

Usage

.unchop_children(children, child_col, call = caller_env())

Arguments

children

(list) List of child data frames or NULL elements.

child_col

(character(1), integer(1), or symbol) The column that contains the children of an observation. This column must be a list where each element is either NULL or a data frame with the same columns as x.

call

(environment) The environment to use for error messages.

Value

(data.frame) All non-NULL children combined into one data frame.


Unchop and repair fields

Description

Unchop and repair fields

Usage

.unchop_fields(fields, names_repair, names_clean, .call = caller_env())

Arguments

fields

(character or NULL) The fields to unpack. If fields is NULL (default), all fields are unpacked.

names_repair

(character(1) or function) Passed to the repair argument of vctrs::vec_as_names() to check that the output data frame has valid names. Must be one of the following options:

  • "unique" (the default) or "unique_quiet": make sure names are unique and not empty,

  • "universal" or "universal_quiet": make the names unique and syntactic

  • "check_unique": no name repair, but check they are unique,

  • a function: apply custom name repair.

names_clean

(function) A one-argument function to clean names after repairing. For example use camel_case_to_snake_case().

.call

(environment) The environment to use for error messages.

Value

(list) A list of unchopped and repaired fields.


Unclass a list_of child data frame

Description

Unclass a list_of child data frame

Usage

.unclass_list_of(x, child_col, call = caller_env())

Arguments

x

(data.frame or NULL) A single child data frame.

child_col

(character(1)) Name of the column that may itself be a vctrs_list_of.

call

(environment) The environment to use for error messages.

Value

(data.frame or NULL) x with vctrs_list_of classes removed, or NULL if x is NULL.


Unpack a single field

Description

Unpack a single field

Usage

.unpack_field(
  field_spec,
  recurse,
  name,
  names_sep,
  names_repair,
  names_clean,
  .call
)

Arguments

field_spec

(tib_collector) A tibblify field collector.

recurse

(logical(1)) Should fields inside other fields be unpacked?

name

(character(1)) The name of the field.

names_sep

(character(1) or NULL) If NULL, the default, the inner names of fields are used. If a string, the outer and inner names are pasted together, separated by names_sep.

names_repair

(character(1) or function) Passed to the repair argument of vctrs::vec_as_names() to check that the output data frame has valid names. Must be one of the following options:

  • "unique" (the default) or "unique_quiet": make sure names are unique and not empty,

  • "universal" or "universal_quiet": make the names unique and syntactic

  • "check_unique": no name repair, but check they are unique,

  • a function: apply custom name repair.

names_clean

(function) A one-argument function to clean names after repairing. For example use camel_case_to_snake_case().

.call

(environment) The environment to use for error messages.

Value

(list) A list of unpacked fields.


Recursively unpack a field

Description

Recursively unpack a field

Usage

.unpack_field_recursive(
  field_spec,
  recurse,
  names_sep,
  names_repair,
  names_clean,
  .call
)

Arguments

field_spec

(tib_collector) A tibblify field collector.

recurse

(logical(1)) Should fields inside other fields be unpacked?

names_sep

(character(1) or NULL) If NULL, the default, the inner names of fields are used. If a string, the outer and inner names are pasted together, separated by names_sep.

names_repair

(character(1) or function) Passed to the repair argument of vctrs::vec_as_names() to check that the output data frame has valid names. Must be one of the following options:

  • "unique" (the default) or "unique_quiet": make sure names are unique and not empty,

  • "universal" or "universal_quiet": make the names unique and syntactic

  • "check_unique": no name repair, but check they are unique,

  • a function: apply custom name repair.

names_clean

(function) A one-argument function to clean names after repairing. For example use camel_case_to_snake_case().

.call

(environment) The environment to use for error messages.

Value

(tib_collector) The field spec with updated sub-fields.


Unpack a row field

Description

Unpack a row field

Usage

.unpack_field_row(field_spec, name, names_sep)

Arguments

field_spec

(tib_collector) A tibblify field collector.

name

(character(1)) The name of the field.

names_sep

(character(1) or NULL) If NULL, the default, the inner names of fields are used. If a string, the outer and inner names are pasted together, separated by names_sep.

Value

(list) A list of unpacked fields from the row spec.


Unpack and repair fields

Description

Unpack and repair fields

Usage

.unpack_fields(
  spec,
  fields,
  recurse,
  names_sep,
  names_repair,
  names_clean,
  .call = caller_env()
)

Arguments

spec

(tspec) A tibblify specification.

fields

(character or NULL) The fields to unpack. If fields is NULL (default), all fields are unpacked.

recurse

(logical(1)) Should fields inside other fields be unpacked?

names_sep

(character(1) or NULL) If NULL, the default, the inner names of fields are used. If a string, the outer and inner names are pasted together, separated by names_sep.

names_repair

(character(1) or function) Passed to the repair argument of vctrs::vec_as_names() to check that the output data frame has valid names. Must be one of the following options:

  • "unique" (the default) or "unique_quiet": make sure names are unique and not empty,

  • "universal" or "universal_quiet": make the names unique and syntactic

  • "check_unique": no name repair, but check they are unique,

  • a function: apply custom name repair.

names_clean

(function) A one-argument function to clean names after repairing. For example use camel_case_to_snake_case().

.call

(environment) The environment to use for error messages.

Value

(list) A list of unpacked fields.


Unpack all fields in a spec

Description

Unpack all fields in a spec

Usage

.unpack_fields_impl(
  spec,
  fields,
  recurse,
  names_sep,
  names_repair,
  names_clean,
  .call = caller_env()
)

Arguments

spec

(tspec) A tibblify specification.

fields

(character or NULL) The fields to unpack. If fields is NULL (default), all fields are unpacked.

recurse

(logical(1)) Should fields inside other fields be unpacked?

names_sep

(character(1) or NULL) If NULL, the default, the inner names of fields are used. If a string, the outer and inner names are pasted together, separated by names_sep.

names_repair

(character(1) or function) Passed to the repair argument of vctrs::vec_as_names() to check that the output data frame has valid names. Must be one of the following options:

  • "unique" (the default) or "unique_quiet": make sure names are unique and not empty,

  • "universal" or "universal_quiet": make the names unique and syntactic

  • "check_unique": no name repair, but check they are unique,

  • a function: apply custom name repair.

names_clean

(function) A one-argument function to clean names after repairing. For example use camel_case_to_snake_case().

.call

(environment) The environment to use for error messages.

Value

(list) A list of unpacked fields (still nested in a list structure).


Update the key of an unpacked field

Description

Update the key of an unpacked field

Usage

.unpack_key(field, key)

Arguments

field

(tib_collector) The field spec being unpacked.

key

(character) The key to prepend.

Value

(tib_collector) The field with updated key.


Untibblify a data frame into a list of row lists

Description

Untibblify a data frame into a list of row lists

Usage

.untibblify_df(x, spec, call = caller_env())

Arguments

x

(any) The object to check.

spec

(tspec or NULL) A spec object describing the structure of x.

call

(environment) The environment to use for error messages.

Value

A list with one named list per row of x.


Untibblify a named list using a spec

Description

Untibblify a named list using a spec

Usage

.untibblify_list(x, spec, call = caller_env())

Arguments

x

(any) The object to check.

spec

(tspec or NULL) A spec object describing the structure of x.

call

(environment) The environment to use for error messages.

Value

A named list with fields converted according to spec.


Untibblify a single list element

Description

Untibblify a single list element

Usage

.untibblify_list_elt(x, field_spec, call = caller_env())

Arguments

x

(any) The object to check.

field_spec

(tib_collector) A tibblify field collector.

call

(environment) The environment to use for error messages.

Value

The converted element, or x unchanged if no conversion applies.


Untibblify a single data frame row into a named list

Description

Untibblify a single data frame row into a named list

Usage

.untibblify_row(x, spec, call = caller_env())

Arguments

x

(any) The object to check.

spec

(tspec or NULL) A spec object describing the structure of x.

call

(environment) The environment to use for error messages.

Value

A named list with one element per field of x.


Update the required status of field specs

Description

Update the required status of field specs

Usage

.update_required_fields(fields, required)

Arguments

fields

(list) A named list of tib field specs.

required

(logical) A named logical vector of required statuses, as returned by .get_required().

Value

fields with the ⁠$required⁠ component of each spec updated.


Flatten a list to a vector

Description

Flatten a list to a vector

Usage

.vec_flatten(x, ptype, name_spec = zap())

Arguments

x

(any) The object to check.

ptype

(vector(0)) A prototype of the desired output type of the field.

name_spec

(character(1), function, or NULL) Name specification passed to vctrs::list_unchop().

Value

A vector with elements from x.


Convert a vector column to a tib scalar or unspecified specification

Description

Convert a vector column to a tib scalar or unspecified specification

Usage

.vector_col_to_spec(col, name)

Arguments

col

(any) A column from a data frame, which may be a vector, a list, or a nested data frame.

name

(character(1)) The name of the field.

Value

A tib_scalar() or tib_unspecified() specification.


Walk the tree level by level, collecting a snapshot at each depth

Description

Walk the tree level by level, collecting a snapshot at each depth

Usage

.walk_tree_levels(x, id_col, child_col, call)

Arguments

x

(data.frame) The root-level data frame.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

child_col

(character(1), integer(1), or symbol) The column that contains the children of an observation. This column must be a list where each element is either NULL or a data frame with the same columns as x.

call

(environment) The environment to use for error messages.

Value

A list of per-level snapshots, each with elements data, ns, parent_ids, and child_sizes.


Wrap indexed purrr errors with context

Description

Wrap indexed purrr errors with context

Usage

.with_indexed_errors(
  expr,
  message,
  error_call = caller_env(),
  env = caller_env()
)

Arguments

expr

(any) An expression to evaluate and return, with indexed errors wrapped.

message

(character) A cli message template.

error_call

(environment) The environment to use for error messages.

env

(environment) The environment used to evaluate glue fields in message.

Value

The evaluated result of expr, or an error with added context.


Printing tibblify specifications

Description

The print() and format() methods for tibblify specifications provide the code necessary to generate the specification. Function names are color-coded to help visually distinguish different types of collectors.

Usage

## S3 method for class 'tib_collector'
print(x, width = NULL, ..., names = NULL)

## S3 method for class 'tib_scalar'
format(
  x,
  ...,
  .fill = NULL,
  .ptype_inner = NULL,
  .transform = NULL,
  multi_line = FALSE,
  nchar_indent = 0,
  width = NULL,
  names = FALSE
)

## S3 method for class 'tib_variant'
format(x, ..., multi_line = FALSE, nchar_indent = 0, width = NULL)

## S3 method for class 'tib_vector'
format(x, ..., multi_line = FALSE, nchar_indent = 0, width = NULL)

## S3 method for class 'tib_unspecified'
format(
  x,
  ...,
  .fill = NULL,
  .ptype_inner = NULL,
  .transform = NULL,
  multi_line = FALSE,
  nchar_indent = 0,
  width = NULL,
  names = FALSE
)

## S3 method for class 'tib_scalar_chr_date'
format(x, ..., multi_line = FALSE, nchar_indent = 0, width = NULL)

## S3 method for class 'tib_vector_chr_date'
format(x, ..., multi_line = FALSE, nchar_indent = 0, width = NULL)

## S3 method for class 'tib_row'
format(x, ..., width = NULL, names = NULL)

## S3 method for class 'tib_df'
format(x, ..., width = NULL, names = NULL)

## S3 method for class 'tib_recursive'
format(x, ..., width = NULL, names = NULL)

## S3 method for class 'tibblify_object'
print(x, ...)

## S3 method for class 'tspec'
print(x, width = NULL, ..., names = NULL)

## S3 method for class 'tspec_df'
format(x, width = NULL, ..., names = NULL)

## S3 method for class 'tspec_row'
format(x, width = NULL, ..., names = NULL)

## S3 method for class 'tspec_recursive'
format(x, width = NULL, ..., names = NULL)

## S3 method for class 'tspec_object'
format(x, width = NULL, ..., names = NULL)

Arguments

x

(any) The spec to format or print.

width

(integer(1)) The width (in number of characters) of text output to generate.

...

These dots are for future extensions and must be empty.

names

(logical(1)) Should names be printed even if they can be deduced from the spec?

.fill

(vector or NULL) Optionally, a value to use if the field does not exist. Note: this value must match the .ptype_inner of the field (the value before any transformation), not the .ptype.

.ptype_inner

(vector(0)) A prototype of the input field.

.transform

(function or NULL) A function to apply to the whole vector after casting to .ptype_inner.

multi_line

(logical(1)) Should the output be formatted across multiple lines? For example, should each element of even a short list be displayed on its own line?

nchar_indent

(integer(1)) The number of (additional) characters that will be used to indent the output when multi_line = TRUE. Primarily for internal use when formatting is applied recursively.

Value

For print() methods, x is returned invisibly. format() methods return a length-1 character vector.

Examples

spec <- tspec_df(
  a = tib_int("a"),
  new_name = tib_chr("b"),
  row = tib_row(
    "row",
    x = tib_int("x")
  )
)
print(spec, names = FALSE)
print(spec, names = TRUE)

Examine the column specification

Description

Examine the column specification

Usage

get_spec(x)

Arguments

x

(data.frame) The data frame to extract a spec from.

Value

A tibblify specification as returned by tspec_df(), tspec_row(), tspec_object(), or tspec_recursive().

Examples

df <- tibblify(list(list(x = 1, y = "a"), list(x = 2)))
get_spec(df)

Guess the tibblify() specification

Description

guess_tspec() automatically dispatches to the other ⁠guess_tspec_*()⁠ functions based on the shape of the input. If you are unhappy with its output, calling a specific ⁠guess_tspec_*()⁠ function may yield better results, or at least clearer error messages about why that type isn't supported.

See vignette("supported-structures") for a discussion of the input types supported by tibblify.

Usage

guess_tspec(
  x,
  ...,
  empty_list_unspecified = FALSE,
  simplify_list = FALSE,
  inform_unspecified = should_inform_unspecified(),
  call = rlang::caller_env()
)

guess_tspec_df(
  x,
  ...,
  empty_list_unspecified = FALSE,
  simplify_list = FALSE,
  inform_unspecified = should_inform_unspecified(),
  call = rlang::current_call(),
  arg = rlang::caller_arg(x)
)

guess_tspec_list(
  x,
  ...,
  empty_list_unspecified = FALSE,
  simplify_list = FALSE,
  inform_unspecified = should_inform_unspecified(),
  arg = caller_arg(x),
  call = current_call()
)

guess_tspec_object(
  x,
  ...,
  empty_list_unspecified = FALSE,
  simplify_list = FALSE,
  inform_unspecified = should_inform_unspecified(),
  call = rlang::current_call()
)

guess_tspec_object_list(
  x,
  ...,
  empty_list_unspecified = FALSE,
  simplify_list = FALSE,
  inform_unspecified = should_inform_unspecified(),
  arg = caller_arg(x),
  call = current_call()
)

Arguments

x

(list or data.frame) A nested list or a data frame.

...

These dots are for future extensions and must be empty.

empty_list_unspecified

(logical(1)) Treat empty lists as unspecified?

simplify_list

(logical(1)) Should scalar lists be simplified to vectors?

inform_unspecified

(logical(1)) Inform about fields whose type could not be determined?

call

(environment) The environment to use for error messages.

arg

(character(1)) An argument name. This name will be mentioned in error messages as the input that is at the origin of a problem.

Value

A specification object that can be used in tibblify().

Examples

guess_tspec(list(x = 1, y = "a"))
guess_tspec(list(list(x = 1), list(x = 2)))

Convert a data frame to a tree

Description

Recursively nest data frame rows based on parent-child relationships, defined by an id column and a parent column. Children become sub-tibbles of their parent rows. This structure is intended for representing tree-like data, such as organizational charts, file systems, category trees, or any other hierarchical relationships.

Usage

nest_tree(x, id_col, parent_col, children_to)

Arguments

x

(data.frame) The data frame to nest.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

parent_col

(character(1), integer(1), or symbol) The column that identifies the parent id of each observation. Each value must either be missing (for the root elements) or appear in the id_col column.

children_to

(character(1)) The column name in which to store the children.

Value

A tree-like, recursively nested data frame.

Examples

df <- tibble::tibble(
  id = 1:5,
  x = letters[1:5],
  parent = c(NA, NA, 1L, 2L, 4L)
)
df

# Only the root elements are in the top-level tibble.
out <- nest_tree(df, id, parent, "children")
out

# The children of each element are stored in the "children" column.
out$children

# "d" (id 4) is a child of "b" (id 2), and "e" (id 5) is a child of "d"
# (id 4).
out$children[[2]]$children

Parse an OpenAPI spec

Description

[Experimental]

The OpenAPI Initiative is a Linux Foundation project to define an OpenAPI Specification, a formal standard for describing HTTP APIs. Use parse_openapi_spec() to parse such OpenAPI specs. You can also parse OpenAPI Schema Objects (which describe the structure of input and output datatypes) directly with parse_openapi_schema().

Usage

parse_openapi_spec(file)

parse_openapi_schema(file)

Arguments

file

(character(1)) A path to a file, a connection, or literal data.

Value

For parse_openapi_spec(), a nested data frame with the columns

For parse_openapi_schema(), a tibblify spec. All references (⁠$ref⁠) in the spec are resolved.

Shortcomings

This implementation is not complete, and there are some known shortcomings:

Examples

file <- '{
  "$schema": "http://json-schema.org/draft-04/schema",
  "title": "Starship",
  "description": "A vehicle.",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "The name of this vehicle. The common name, e.g. Sand Crawler."
    },
    "model": {
      "type": "string",
      "description": "The model or official name of this vehicle."
    },
    "url": {
      "type": "string",
      "format": "uri",
      "description": "The hypermedia URL of this resource."
    },
    "edited": {
      "type": "string",
      "format": "date-time",
      "description": "the ISO 8601 date format of the time this resource was edited."
    }
  },
  "required": [
    "name",
    "model",
    "edited"
  ]
}'
parse_openapi_schema(file)

# Spec example from
# https://swagger.io/docs/specification/v3_0/basic-structure/
spec_path <- system.file(
  "examples", "openapi", "sample_api.yaml", package = "tibblify"
)
spec <- parse_openapi_spec(spec_path)
spec

Politicians

Description

A dataset containing some basic information about some politicians.

Usage

politicians

Format

A list of lists.


Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

rlang

zap()

tibble

tibble()


Determine whether to inform about unspecified fields in spec

Description

Wrapper around getOption("tibblify.show_unspecified") to return TRUE unless the option is explicitly set to FALSE.

Usage

should_inform_unspecified()

Value

FALSE if the option is set to FALSE, TRUE otherwise.

Examples

should_inform_unspecified()

Create a field specification

Description

Use the ⁠tib_*()⁠ functions to specify how to process the fields of an object.

Usage

tib_scalar(
  .key,
  .ptype,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = .ptype,
  .transform = NULL,
  key = deprecated(),
  ptype = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated()
)

tib_vector(
  .key,
  .ptype,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = .ptype,
  .transform = NULL,
  .elt_transform = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  key = deprecated(),
  ptype = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated(),
  elt_transform = deprecated(),
  input_form = deprecated(),
  values_to = deprecated(),
  names_to = deprecated()
)

tib_unspecified(
  .key,
  ...,
  .required = TRUE,
  key = deprecated(),
  required = deprecated()
)

tib_lgl(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = logical(),
  .transform = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated()
)

tib_int(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = integer(),
  .transform = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated()
)

tib_dbl(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = double(),
  .transform = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated()
)

tib_chr(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = character(),
  .transform = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated()
)

tib_date(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = vctrs::new_date(),
  .transform = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated()
)

tib_chr_date(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .format = "%Y-%m-%d",
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  format = deprecated()
)

tib_lgl_vec(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = logical(),
  .transform = NULL,
  .elt_transform = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated(),
  elt_transform = deprecated(),
  input_form = deprecated(),
  values_to = deprecated(),
  names_to = deprecated()
)

tib_int_vec(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = integer(),
  .transform = NULL,
  .elt_transform = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated(),
  elt_transform = deprecated(),
  input_form = deprecated(),
  values_to = deprecated(),
  names_to = deprecated()
)

tib_dbl_vec(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = double(),
  .transform = NULL,
  .elt_transform = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated(),
  elt_transform = deprecated(),
  input_form = deprecated(),
  values_to = deprecated(),
  names_to = deprecated()
)

tib_chr_vec(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = character(),
  .transform = NULL,
  .elt_transform = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated(),
  elt_transform = deprecated(),
  input_form = deprecated(),
  values_to = deprecated(),
  names_to = deprecated()
)

tib_date_vec(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .ptype_inner = vctrs::new_date(),
  .transform = NULL,
  .elt_transform = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  ptype_inner = deprecated(),
  transform = deprecated(),
  elt_transform = deprecated(),
  input_form = deprecated(),
  values_to = deprecated(),
  names_to = deprecated()
)

tib_chr_date_vec(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .input_form = c("vector", "scalar_list", "object"),
  .values_to = NULL,
  .names_to = NULL,
  .format = "%Y-%m-%d",
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  input_form = deprecated(),
  values_to = deprecated(),
  names_to = deprecated(),
  format = deprecated()
)

tib_variant(
  .key,
  ...,
  .required = TRUE,
  .fill = NULL,
  .transform = NULL,
  .elt_transform = NULL,
  key = deprecated(),
  required = deprecated(),
  fill = deprecated(),
  transform = deprecated(),
  elt_transform = deprecated()
)

tib_recursive(.key, ..., .children, .children_to = .children, .required = TRUE)

tib_row(.key, ..., .required = TRUE)

tib_df(.key, ..., .required = TRUE, .names_to = NULL)

Arguments

.key, key

(character) The path of names to the field in the object.

.ptype, ptype

(vector(0)) A prototype of the desired output type of the field.

...

These dots are for future extensions and must be empty.

.required, required

(logical(1)) Throw an error if the field does not exist?

.fill, fill

(vector or NULL) Optionally, a value to use if the field does not exist. Note: this value must match the .ptype_inner of the field (the value before any transformation), not the .ptype.

.ptype_inner, ptype_inner

(vector(0)) A prototype of the input field.

.transform, transform

(function or NULL) A function to apply to the whole vector after casting to .ptype_inner.

.elt_transform, elt_transform

(function or NULL) A function to apply to each element before casting to .ptype_inner.

.input_form, input_form

(character(1)) The structure of the input field. Can be one of:

  • "vector": The field is a vector, e.g. c(1, 2, 3).

  • "scalar_list": The field is a list of scalars, e.g. list(1, 2, 3).

  • "object": The field is a named list of scalars, e.g. list(a = 1, b = 2, c = 3).

.values_to, values_to

(character(1) or NULL) For NULL (the default), the field is converted to a .ptype vector. If a string is provided, the field is converted to a tibble and the values go into the specified column.

.names_to, names_to

(character(1) or NULL) What to do with the inner names of the object. Can be one of:

  • NULL: the default. The inner names of the field are not used.

  • A string: Use only if the input form is "object" or "vector", and .values_to is a string. The inner names of the field will populate the specified column in the field's tibble.

.format, format

(character(1) or NULL) Passed to the format argument of as.Date().

.children

(character(1)) The name of the field that contains the children.

.children_to

(character(1)) The column name in which to store the children.

Details

There are five families of ⁠tib_*()⁠ functions:

Value

A tibblify field collector. This specification can be used with tspec_df() or another ⁠tspec_*()⁠ function to specify how to process an object.

Examples

tib_int("int")
tib_int("int", .required = FALSE, .fill = 0)

# This is essentially how `tib_chr_date()` is implemented.
tib_scalar(
  "date",
  Sys.Date(),
  .transform = function(x) as.Date(x, format = "%Y-%m-%d")
)

tib_df(
  "data",
  .names_to = "id",
  age = tib_int("age"),
  name = tib_chr("name")
)

Rectangle a nested list

Description

Transform a nested list into a tibble or a list of objects according to a specification.

Usage

tibblify(x, spec = NULL, unspecified = NULL)

Arguments

x

(list) A nested list.

spec

(tspec) A specification of how to convert x. Generated with tspec_df(), tspec_row(), tspec_object(), tspec_recursive(), or guess_tspec(). If spec is NULL (the default), guess_tspec(x, inform_unspecified = TRUE) will be used to guess the spec.

unspecified

(character(1)) What to do with tib_unspecified() fields. Can be one of

  • "error": Throw an error.

  • "inform": Inform the user then parse as with tib_variant().

  • "drop": Do not parse these fields.

  • "list": Parse unspecified fields into lists as with tib_variant().

Details

Fields specifically tagged as tib_unspecified() in the spec (or guessed as such) will be handled according to the unspecified argument. Fields that are present in x but not mentioned in the spec are ignored.

Value

Either a tibble or a list, depending on the specification.

See Also

Use untibblify() to undo the result of tibblify().

Examples

# List of Objects -----------------------------------------------------------
x <- list(
  list(id = 1, name = "Tyrion Lannister"),
  list(id = 2, name = "Victarion Greyjoy")
)
tibblify(x)

# Provide a specification
spec <- tspec_df(
  id = tib_int("id"),
  name = tib_chr("name")
)
tibblify(x, spec)

# Object --------------------------------------------------------------------
# Provide a specification for a single object
tibblify(x[[1]], tspec_object(spec))

# Recursive Trees -----------------------------------------------------------
x <- list(
  list(
    id = 1,
    name = "a",
    children = list(
      list(id = 11, name = "aa"),
      list(id = 12, name = "ab", children = list(
        list(id = 121, name = "aba")
      ))
    ))
)
spec <- tspec_recursive(
  tib_int("id"),
  tib_chr("name"),
  .children = "children"
)
out <- tibblify(x, spec)
out
out$children
out$children[[1]]$children[[2]]

Combine multiple specifications

Description

Combine specifications created by tspec_df(), tspec_row(), or tspec_object(). The resulting specification includes all fields from the input specifications.

Usage

tspec_combine(...)

Arguments

...

(tspec) Specifications to combine.

Details

If a field is specified in multiple input specifications, the field specifications will be combined to produce a single field specification, using the most specific specification for each argument. See the examples for details.

Value

A tibblify specification.

Examples

# union of fields
tspec_combine(
  tspec_df(tib_int("a")),
  tspec_df(tib_chr("b"))
)

# unspecified + x -> x
tspec_combine(
  tspec_df(tib_unspecified("a")),
  tspec_df(tib_int("a"))
)

# scalar + vector -> vector
tspec_combine(
  tspec_df(tib_chr("a")),
  tspec_df(tib_chr_vec("a"))
)

# scalar/vector + variant -> variant
tspec_combine(
  tspec_df(tib_chr("a")),
  tspec_df(tib_chr_vec("a")),
  tspec_df(tib_variant("a"))
)

Create a tibblify specification

Description

Use tspec_df() to specify how to convert a list of objects to a tibble. Use tspec_row() to specify how to convert an object to a one-row tibble. Use tspec_object() to specify how to convert an object to a list.

Usage

tspec_df(
  ...,
  .input_form = c("rowmajor", "colmajor"),
  .names_to = NULL,
  .vector_allows_empty_list = FALSE,
  vector_allows_empty_list = deprecated()
)

tspec_object(
  ...,
  .input_form = c("rowmajor", "colmajor"),
  .vector_allows_empty_list = FALSE,
  vector_allows_empty_list = deprecated()
)

tspec_row(
  ...,
  .input_form = c("rowmajor", "colmajor"),
  .vector_allows_empty_list = FALSE,
  vector_allows_empty_list = deprecated()
)

tspec_recursive(
  ...,
  .children,
  .children_to = .children,
  .input_form = c("rowmajor", "colmajor"),
  .vector_allows_empty_list = FALSE,
  vector_allows_empty_list = deprecated()
)

Arguments

...

(tib_collector or tspec) Column specifications created by ⁠tib_*()⁠ or ⁠tspec_*()⁠. If the dots are named, the name will be used for the resulting column. Otherwise, the name of the input will be used for the column name.

.input_form

(character(1)) The input form of data-frame-like lists. Can be one of:

  • "rowmajor": The default. The input is a named list of rows.

  • "colmajor": The input is a named list of columns.

.names_to

(character(1) or NULL) The name of the column in the output which will contain the names of top-level elements of the input named list. If NULL, the default, no name column is created.

.vector_allows_empty_list, vector_allows_empty_list

(logical(1)) Should empty lists for columns with .input_form = "vector" be accepted and treated as empty vectors?

.children

(character(1)) The name of the field that contains the children.

.children_to

(character(1)) The column name in which to store the children.

Details

In column-major format, all fields are required, regardless of the .required argument.

Value

A tibblify specification.

Examples

tspec_df(
  id = tib_int("id"),
  name = tib_chr("name"),
  aliases = tib_chr_vec("aliases")
)

# Equivalent to
tspec_df(
  tib_int("id"),
  tib_chr("name"),
  tib_chr_vec("aliases")
)

# To create multiple columns of the same type use the bang-bang-bang (`!!!`)
# operator together with `purrr::map()`
tspec_df(
  !!!purrr::map(rlang::set_names(c("id", "age")), tib_int),
  !!!purrr::map(rlang::set_names(c("name", "title")), tib_chr)
)

# The `tspec_*()` functions can also be nested
spec1 <- tspec_object(
  int = tib_int("int"),
  chr = tib_chr("chr")
)
spec2 <- tspec_object(
  int2 = tib_int("int2"),
  chr2 = tib_chr("chr2")
)

tspec_df(spec1, spec2)

Unnest a recursive data frame

Description

Unnest a recursive data frame

Usage

unnest_tree(
  x,
  id_col,
  child_col,
  level_to = "level",
  parent_to = "parent",
  ancestors_to = NULL
)

Arguments

x

(data.frame) The data frame to unnest.

id_col

(character(1), integer(1), or symbol) The column that uniquely identifies each observation.

child_col

(character(1), integer(1), or symbol) The column that contains the children of an observation. This column must be a list where each element is either NULL or a data frame with the same columns as x.

level_to

(character(1)) The column name ("level" by default) in which to store the level of an observation. Use NULL if you don't need this information.

parent_to

(character(1)) The column name ("parent" by default) in which to store the parent id of an observation. Use NULL if you don't need this information.

ancestors_to

(character(1)) The column name (NULL by default) in which to store the ids of the ancestors of a deeply nested child. Use NULL if you don't need this information.

Value

A "flat" data frame.

Examples

df <- tibble(
  id = 1L,
  name = "a",
  children = list(
    tibble(
      id = 11:12,
      name = c("b", "c"),
      children = list(
        NULL,
        tibble(
          id = 121:122,
          name = c("d", "e")
        )
      )
    )
  )
)
df

unnest_tree(
  df,
  id_col = "id",
  child_col = "children",
  level_to = "level",
  parent_to = "parent",
  ancestors_to = "ancestors"
)

Unpack a tibblify specification

Description

tidyr::unpack() makes data wider by expanding df-columns into individual columns. Analogously, unpacking a tibblify specification makes a specification which will result in a wider tibble by expanding tib_row() specifications into their individual fields.

Usage

unpack_tspec(
  spec,
  ...,
  fields = NULL,
  recurse = TRUE,
  names_sep = NULL,
  names_repair = c("unique", "universal", "check_unique", "unique_quiet",
    "universal_quiet"),
  names_clean = NULL
)

camel_case_to_snake_case(x)

Arguments

spec

(tspec) A tibblify specification.

...

These dots are for future extensions and must be empty.

fields

(character or NULL) The fields to unpack. If fields is NULL (default), all fields are unpacked.

recurse

(logical(1)) Should fields inside other fields be unpacked?

names_sep

(character(1) or NULL) If NULL, the default, the inner names of fields are used. If a string, the outer and inner names are pasted together, separated by names_sep.

names_repair

(character(1) or function) Passed to the repair argument of vctrs::vec_as_names() to check that the output data frame has valid names. Must be one of the following options:

  • "unique" (the default) or "unique_quiet": make sure names are unique and not empty,

  • "universal" or "universal_quiet": make the names unique and syntactic

  • "check_unique": no name repair, but check they are unique,

  • a function: apply custom name repair.

names_clean

(function) A one-argument function to clean names after repairing. For example use camel_case_to_snake_case().

x

(character) CamelCase text to convert to snake_case.

Value

A tibblify spec.

Examples

spec <- tspec_df(
  tib_lgl("a"),
  tib_row("x", tib_int("b"), tib_chr("c")),
  tib_row("y", tib_row("z", tib_chr("d")))
)
unpack_tspec(spec)
# only unpack `x`
unpack_tspec(spec, fields = "x")
# do not unpack the fields in `y`
unpack_tspec(spec, recurse = FALSE)
camel_case_to_snake_case(c("ExampleText", "otherTextToConvert"))

Convert a data frame or object into a nested list

Description

Convert a data frame or an object into a nested list. This is the inverse operation of tibblify(). See vignette("supported-structures") for a description of objects recognized by tibblify.

Usage

untibblify(x, spec = get_spec(x))

Arguments

x

(data.frame or object) An object to convert into a nested list.

spec

(tspec) Optional. A spec object which was used to create x. Defaults to the spec stored as the tib_spec attribute of x, if present.

Value

A nested list.

Examples

x <- tibble(
  a = 1:2,
  b = tibble(
    x = c("a", "b"),
    y = c(1.5, 2.5)
  )
)
untibblify(x)