gloss_factory {glossr}R Documentation

Function factory to print glosses from dataframe

Description

This function takes a dataframe with glosses and returns another function that takes either an id or list of ids (if use_conditionals is FALSE) or a conditional statement (if TRUE) and runs gloss_df() on the filtered dataframe.

Usage

gloss_factory(
  glosses,
  use_conditionals = FALSE,
  id_column = "label",
  ignore_columns = NULL,
  validate = TRUE
)

Arguments

glosses

Dataframe with gloss data.

use_conditionals

Boolean. If TRUE, the returned function will use conditional statements to filter the dataframe. Otherwise, it will use ids and match them to the values in the id_column.

id_column

Name of the column with ids for filtering, if use_conditionals is FALSE.

ignore_columns

Optional character vector with names of columns that could be used for filtering but should not be provided to gloss_df().

validate

Boolean. If TRUE, running gloss_factory() will print a few informative messages about how glossr is reading the dataframe.

Value

A function.

If use_conditionals is FALSE (the default), the returned function will take a character vector or a series of character vectors with id's to filter. If id_column is "label", running that function will be the equivalent to filtering glosses based on the values in the label column.

If use_conditionals is TRUE, the returned function will take the same conditions that a dplyr::filter() would.

Examples

my_glosses <- dplyr::select(glosses, -language)
by_label <- gloss_factory(my_glosses)

by_label("heartwarming-jp")

by_label("heartwarming-jp", "languid-jp")

by_cond <- gloss_factory(my_glosses, use_conditional = TRUE)
by_cond(stringr::str_ends(label, "jp"))

[Package glossr version 0.8.0 Index]