Package {LexOPS}


Title: Selecting Matched Items for Factorial Designs
Version: 0.6.4
Date: 2026-11-09
Description: Select controlled items for factorial designs, matched with exact tolerances on any number of variables. Also supports (and can be combined with) matching on Euclidean distances and the outputs of functions. Full documentation is available at https://jackedtaylor.github.io/LexOPSdocs/. There is a 'shiny' app built with GUIs which supports most package functionality. The package is described by Taylor et al. (2020) <doi:10.3758/s13428-020-01389-1>.
License: GPL-3
Encoding: UTF-8
VignetteBuilder: knitr
Imports: rlang, pak, ggplot2, stats, scales, magrittr
Suggests: lexopsdata (≥ 0.0.1), stringr, tidyr, tibble, dplyr, purrr, knitr, rmarkdown, testthat (≥ 2.1.0), shiny, plotly, ggwordcloud, shinydashboard, colourpicker, shinycssloaders, shinyjs, viridis, stringdist, DT, readr, forcats
Additional_repositories: https://JackEdTaylor.github.io/lexopsdata
URL: https://JackEdTaylor.github.io/LexOPSdocs/, https://github.com/JackEdTaylor/LexOPS/
BugReports: https://github.com/JackEdTaylor/LexOPS/issues
Config/roxygen2/version: 8.1.0
NeedsCompilation: no
Packaged: 2026-11-09 08:13:21 UTC; Jack
Author: Jack Taylor ORCID iD [aut, cre], Alistair Beith ORCID iD [aut]
Maintainer: Jack Taylor <Taylor@psych.uni-frankfurt.de>
Depends: R (≥ 4.1.0)
Repository: CRAN
Date/Publication: 2026-12-01 15:00:09 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Value

No return value (syntactic alias for rhs(lhs())).

Examples

c(1, 4, 2, 7) %>%
  sum()


Walrus operator

Description

See rlang::quasiquotation for details.

Value

No return value (syntactic alias for =).

Examples

# example from rlang::quasiquotation
name <- "foo"

rbind2 <- function(...) {
  do.call("rbind", rlang::list2(...))
}

rbind2("{name}" := 1:2, bar = 3:4)


Set an object's class to LexOPS_pipeline

Description

Set an object's class to LexOPS_pipeline

Usage

as.LexOPS_pipeline(x)

Arguments

x

Object, ultimately of class data.frame, possibly resulting from one of split_by, control_for, etc..

Value

x, coerced into class LexOPS_pipeline

Examples

as.LexOPS_pipeline(lexops)


Generate a box's visualisation

Description

Function for generating a visualisation for a box's selected options

Usage

box_vis(
  var,
  box_type = "primary",
  tol = NA,
  match_string = NA,
  shade_label = NA,
  shade_relative = TRUE,
  cat_vis = NA,
  df = lexopsdata::lexops
)

Arguments

var

Character vector specifying which variable is selected

box_type

Which type of box is it? (one of: "primary", "warning", "success", "danger", and "info")

tol

The area which should be highlighted. Can be a numeric vector of length two, a character vector of acceptable categories, or a list of such vectors. Each item in a tol list specifies one level.

match_string

If the variable is being matched for, which string is it relative to. Leave as NA if not a matching box.

shade_label

A character vector specifying what to label the levels. Order should match that of tol. Leave as NA if not doing a split.

shade_relative

If TRUE, the value of tol is taken to be relative to the value for match_string. If FALSE, the raw values of tol are used. If match_string is not defined, shade_relative has no effect. Default is TRUE.

cat_vis

which category should be highlighted (if a categorical variable)? Can be one of tol or match_string_val.

df

A dataframe. Default is lexops.

Value

A ggplot2 or ggwordcloud object with the required visualisation.


Generate a question mark plot

Description

Function for generating a visualisation of question marks surrounding a message

Usage

box_vis.question_marks(message, box_type)

Arguments

message

A string; the message to display.

box_type

The type of box the visualisation is presented in.

Value

A ggplot2 or ggwordcloud object with the required visualisation.


Generate a citation

Description

Get the measure name, source, and url for any vector of column names from lexops.

Usage

citation_table(cite_vars)

Arguments

cite_vars

A character vector of column names

Value

A tibble that lists measures and sources of data that should be cited (if known).

Examples


citation_table(c("PK.Brysbaert", "HUM.Engelthaler"))


Generate a citation

Description

Takes the output from generate or long_format, and generates a tibble that lists known references that should be cited. This function will only be useful if you use variables from the lexops dataset (lexops) with their original names.

Usage

cite_design(df, include = "design")

Arguments

df

Output from generate or long_format functions.

include

A string indicating which variables to include in the citation. This can be those specified by split_by and control_for ("design"), only those specified in split_by ("splits"), or only those specified by control_for ("controls"). Alternatively, this can be a character vector of the variables that should be cited, that were in the original dataframe. Default is "design".

Value

A tibble that lists measures and sources of data that should be cited (if known).

Examples



library(lexopsdata)

stim <- lexops |>
  split_by(BG.SUBTLEX_UK, 0.001:0.003 ~ 0.009:0.011) |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length) |>
  generate(n = 50, match_null = "balanced")

cite_design(stim)


Control for confounding variables.

Description

Specifies variables that should be controlled for in the generated stimuli, after splitting. Can be run multiple times to control for multiple variables.

Usage

control_for(x, var, tol = NA, standard_eval = FALSE)

Arguments

x

A data frame containing the IV and strings, or a LexOPS_pipeline object resulting from one of split_by, control_for, etc..

var

The column to treat as a control (non-standard evaluation).

tol

The tolerance of the control. For numeric variables, this should be in the form lower:upper (e.g. -0.1:0.1 will control within +/- 0.1). For categorical variables, this can be kept as NA.

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R objects in var and tol. If TRUE, var should be a character vector referring to a column in df (e.g. "Zipf.SUBTLEX_UK"), and tol should be a vector of length 2, specifying the tolerance (e.g. c(-0.1, 0.5)). Default = FALSE.

Value

A LexOPS_pipeline object, with details on the variables to be controlled for added to the attributes. Run the generate function to then generate the actual stimuli.

Examples



library(lexopsdata)

# Create 3 levels of syllables, for 1-3, 4-6, and 7-20 syllables, and control for word frequency
lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6 ~ 7:20) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2)

# Control for multiple variables
lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6 ~ 7:20) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(PoS.SUBTLEX_UK)

# Bypass non-standard evaluation
lexops |>
 split_by("Syllables.CMU", list(c(1, 3), c(4, 6), c(7, 20)), standard_eval = TRUE) |>
 control_for("Zipf.SUBTLEX_UK", c(-0.2, 0.2), standard_eval = TRUE) |>
 control_for("PoS.SUBTLEX_UK", standard_eval = TRUE)


Control for Euclidean distance in several numeric variables

Description

This function is a wrapper for control_for_map that allows you to easily control for Euclidean distance.

Usage

control_for_euc(
  x,
  vars,
  tol,
  name = NA,
  scale = TRUE,
  center = TRUE,
  weights = NA,
  standardise_weights = TRUE,
  euc_df = NA,
  standard_eval = FALSE
)

Arguments

x

A data frame containing the IV and strings, or a LexOPS_pipeline object resulting from one of split_by, control_for, etc..

vars

The columns from which to calculate Euclidean distance.

tol

The desired control tolerance, in Euclidean distance (will be interpreted as scaled Euclidean distance if scaled == TRUE).

name

What the output column should be named. If NA (default), will automatically assign as sprintf("control_fun_%i", nr), where nr is the number of the control function.

scale, center

How should variables be scaled and/or centred before calculating Euclidean distance? For options, see the scale and center arguments of scale. Default for both is TRUE. Scaling can be useful when variables are in differently scaled.

weights

An (optional) list of weights, in the same order as vars. After any scaling is applied, the values will be multiplied by these weights. Default is NA, meaning all variables are weighted equally.

standardise_weights

Logical; should the weights be standardised to average to 1 (i.e., sum to the length of vars)? If TRUE, weights=c(1, 3, 6) will be treated as weights=c(0.3, 0.6, 1.8). Setting standardise_weights=TRUE ensures that the space itself is unchanged when weights change. This means that the same tolerance can be used when the weights change.

euc_df

The dataframe to calculate the Euclidean distance from. By default, the function will use df. Giving a different dataframe to euc_df can be useful in some cases, such as when df has been filtered for generating stimuli, but you want to calculate Euclidean Distance from a full distribution.

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R objects in vars and tol. If TRUE, vars should be a character vector referring to columns in df (e.g. c("Zipf.SUBTLEX_UK", "Length")), and tol should be a vector of length 2, specifying the tolerance (e.g. c(0, 0.5)). Default = FALSE.

Details

The long format version of the generated items (long_format) will include a column, with the name defined by the name argument. This will include the calculated Euclidean distances. If the match null is set in generate to be inclusive (match_null="inclusive") and there are more than two factorial cells, this column will contain the maximum of all Euclidean distances for a given item.

Value

A LexOPS_pipeline object, where df has details on the variables to be controlled for added to the attributes. Run the generate function to then generate the actual stimuli.

Examples



library(lexopsdata)

stim <- lexops |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  control_for_euc(c(Zipf.BNC.Written, Length), 0:0.005)

# bypass non-standard evaluation
stim <- lexops %>%
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  control_for_euc(c("Zipf.BNC.Written", "Length"), c(0, 0.005), standard_eval = TRUE)

# generate stimuli from a subsetted dataframe, but calculate
# Euclidean distance from an (original) unsubsetted dataframe
stim <- lexops |>
  subset(PK.Brysbaert >= 0.9) |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  control_for_euc(
    c(Zipf.SUBTLEX_UK, Length),
    0:0.005,
    name = "Euclidean Distance",
    euc_df = lexops
  )


Control for confounding variables via a function.

Description

Some variables (e.g. similarity measures) are hard to control for with control_for as they need to be recalculated for each word relative to each other, rather than there being a single value for each possible stimulus. The control_for_map() function declares a function that the generate function should apply to each match_null within an iteration of stimulus generation. The function given as fun should be able to take the data in the column given in var as the first argument, and should be able to take the match_null's value in that column as the second argument.

Usage

control_for_map(x, fun, var, tol = NA, name = NA, standard_eval = FALSE, ...)

Arguments

x

A data frame containing the IV and strings, or a LexOPS_pipeline object resulting from one of split_by, control_for, etc..

fun

The function to use to calculate the control variable. Should be an object of class "function".

var

The column to provide the value which will be the first argument of the function.

tol

The tolerance of the control. For numeric variables, this should be in the form lower:upper (e.g. -0.1:0.1 will control within +/- 0.1). For categorical variables, this can be kept as NA.

name

What the output column should be named. If NA (default), will automatically assign as sprintf("control_fun_%i", nr), where nr is the number of the control function.

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R objects in var and tol. If TRUE, var should be a character vector referring to a column in df (e.g. "Zipf.SUBTLEX_UK"), and tol should be a vector of length 2, specifying the tolerance (e.g. c(-0.1, 0.5)). Default = FALSE.

...

Arguments to be passed to fun

Details

The long format version of the generated items (long_format) will include a column, with the name defined by the name argument. This will include the values returned by the function fun. If the match null is set in generate to be inclusive (match_null="inclusive") and there are more than two factorial cells, this column will only contain NAs.

Value

A LexOPS_pipeline object, where df has details on the variables to be controlled for added to the attributes. Run the generate function to then generate the actual stimuli.

Examples



library(lexopsdata)

# Create two levels of arousal, controlling for orthographic similarity
# (as optimal string alignment; default for `stringdist()`)
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, string, 0:4)

# Create two levels of arousal, controlling for orthographic Levenshtein distance
# (passed via `method` argument to `stringdist()`)
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, string, 0:4, method="lv")

# Create two levels of arousal, controlling for phonological Levenshtein distance
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, eSpeak.br_1letter, 0:2, method="lv")

# Bypass non-standard evaluation
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 7:9) |>
 control_for_map(stringdist, "eSpeak.br_1letter", c(0, 2), standard_eval=TRUE, method="lv")

 # Use a function that returns a non-numeric output
 library(stringdist)

 stringdist_okay <- function(target, matches) {
   dist <- stringdist(target, matches, method="lv")
   ifelse(dist <= 4, "okay", "not_okay")
 }

 lexops |>
   split_by(AROU.Warriner, 1:3 ~ 7:9) |>
   control_for_map(stringdist_okay, string, "not_okay")


Calculate a word's Euclidean distance from other words

Description

Caclulates the Euclidean distance of a word from all other words in a df, on selected variables.

Usage

euc_dists(
  df = LexOPS::lexops,
  target,
  vars = "all",
  scale = TRUE,
  center = TRUE,
  weights = NA,
  standardise_weights = TRUE,
  id_col = "string",
  standard_eval = FALSE
)

Arguments

df

A data frame.

target

The target string (word) that euclidean distances are required for.

vars

The variables to be used as dimensions which Euclidean distance should be calculated over. Can be a vector of variable names (e.g. c(Zipf.SUBTLEX_UK, Length)), or, "all", to use all numeric variables in the data frame. The default is "all".

scale, center

How should variables be scaled and/or centred before calculating Euclidean distance? For options, see the scale and center arguments of scale. Default for both is TRUE. Scaling can be useful when variables are in differently scaled.

weights

An (optional) list of weights, in the same order as vars. After any scaling is applied, the values will be multiplied by these weights. Default is NA, meaning no weights are applied.

standardise_weights

Logical; should the weights be standardised to average to 1 (i.e., sum to the length of vars)? If TRUE, weights=c(1, 3, 6) will be treated as weights=c(0.3, 0.6, 1.8). Setting standardise_weights=TRUE ensures that the space itself is unchanged when weights change. This means, for example, that the same tolerance can be used in control_for_euc().

id_col

The column containing the strings (default = "string").

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R objects in vars. If TRUE, vars should be a character vector referring to columns in df (e.g. c("Length", "Zipf.SUBTLEX_UK")). Default = FALSE.

Value

A numeric vector of Euclidean distances, in the order of rows in df.

Examples



library(lexopsdata)

# Get the distance of every entry in the `lexops` dataset from the word "thicket".
# (Note: This will be calculated using the dimensions of frequency, arousal, and size)
lexops |>
  euc_dists("thicket", c(Zipf.SUBTLEX_UK, AROU.Warriner, SIZE.Glasgow_Norms))

# no scaling or centering
lexops |>
  euc_dists(
    "thicket",
    c(Zipf.SUBTLEX_UK, AROU.Warriner, SIZE.Glasgow_Norms),
    scale = FALSE,
    center = FALSE
  )

# Add Euclidean distance as new column
# (Also sort ascendingly by distance; barbara will have a distance of 0 so will be first)
lexops %>%
  dplyr::mutate(ed = euc_dists(., "barbara", c(Length, Zipf.SUBTLEX_UK, BG.SUBTLEX_UK))) |>
  dplyr::arrange(ed)

# bypass non-standard evaluation
lexops |>
  euc_dists(
    "thicket",
    c("Zipf.SUBTLEX_UK", "AROU.Warriner", "SIZE.Glasgow_Norms"),
    standard_eval = TRUE
  )


Get a text summary about a LexOPS pipeline

Description

Generates a text summary of a LexOPS_pipeline object resulting from one of split_by, control_for, etc..

Usage

## S3 method for class 'LexOPS_pipeline'
format(x, ...)

Arguments

x

A LexOPS_pipeline object resulting from one of split_by, control_for, etc., which has not yet been passed through generate.

...

Other arguments passed to or from other methods (unused).

Value

A character vector containing a formatted summary of the LexOPS pipeline.

Examples


library(lexopsdata)

pipeline <- lexops |>
  subset(PK.Brysbaert >= .75) |>
  split_by(BG.SUBTLEX_UK, 0.001:0.003 ~ 0.009:0.011) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length, 0:0)

format(pipeline)


Generate stimuli

Description

Generates the stimuli from the data frame after it has been passed through split_by, and optionally, control_for. Will generate n items per condition. If <n items can be generated, will generate as many as possible given the experiment's design.

Usage

generate(
  x,
  n = 20,
  match_null = "balanced",
  seed = NA,
  silent = FALSE,
  is_shiny = FALSE
)

Arguments

x

A LexOPS_pipeline object resulting from one of split_by, control_for, etc..

n

The number of strings per condition (default = 20). Set to "all" to generate as many as possible.

match_null

The condition that items should be matched to. Should be a string indicating condition (e.g. "A1_B2_C1"), or a string indicating one of the following options: "balanced" for randomly ordered null conditions with (as close to as possible) equal number of selections for each condition (default), "inclusive" to match each condition within the tolerances to every other condition, "first" for the lowest condition (e.g. "A1" or "A1_B1_C1_D1", etc.), "random" for randomly selected null condition each iteration.

seed

Deprecated: set seeds externally (e.g., set.seed()).

silent

Logical: should output to the console (via cat()) be suppressed? Default is FALSE.

is_shiny

Allows printing in a shiny context with shinyjs::html. Outputs from the cat() function are stored in the div with id "gen_console". Default is FALSE.

Value

The generated stimuli, as a dataframe of class LexOPS_pipeline.

See Also

lexops for the data frame used in the examples.

Examples



library(lexopsdata)

# Generate 10 words per condition, for design with 3 levels of syllables, controlled for frequency
lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6 ~ 7:20) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  generate(n = 10)

# Generate 2 levels of bigram probability, controlling for frequency and length
# (Note that the matching null is balanced across all stimuli)
# (Also note that the data is filtered by proportion known to be >75%)
lexops |>
  subset(PK.Brysbaert >= .75) |>
  split_by(BG.SUBTLEX_UK, 0.001:0.003 ~ 0.009:0.011) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length) |>
  generate(n = 10, match_null = "balanced")

# Generate stimuli for a concreteness x valence (2 x 3) design
# (Note that abstract, neutral is set as the matching null)
lexops |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  split_by(VAL.Warriner, 1:3 ~ 4.5:5.5 ~ 7:9) |>
  control_for(Zipf.SUBTLEX_UK, -0.25:0.25) |>
  control_for(Length) |>
  generate(n = 10, match_null = "A2_B2")

# As above but with inclusive tolerance
# (all words are within the specified tolerances relative to each other)
lexops |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  split_by(VAL.Warriner, 1:3 ~ 4.5:5.5 ~ 7:9) |>
  control_for(Zipf.SUBTLEX_UK, -0.25:0.25) |>
  control_for(Length) |>
  generate(n = 10, match_null = "inclusive")

# Bypass non-standard evaluation
lexops |>
 split_by("Syllables.CMU", list(c(1, 3), c(4, 6), c(7, 20)), standard_eval = TRUE) |>
 control_for("Zipf.SUBTLEX_UK", c(-0.2, 0.2), standard_eval = TRUE) |>
 generate(n = 10)

# Create two levels of arousal, controlling for orthographic Levenshtein distance
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 6:9) |>
 control_for_map(stringdist, string, 0:4, method="lv") |>
 generate(10)

# Create two levels of arousal, controlling for phonological similarity
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 6:9) |>
 control_for_map(stringdist, eSpeak.br_1letter, 0:2, method="lv") |>
 generate(10)

# Create two levels of arousal, controlling for phonological Levenshtein distance, and rhyme
library(stringdist)
lexops |>
 split_by(AROU.Warriner, 1:3 ~ 6:9) |>
 control_for(Rhyme.eSpeak.br) |>
 control_for_map(stringdist, eSpeak.br_1letter, 0:2, method="lv") |>
 generate(10)

# A similar design to that above, but with 3 levels of valence, and inclusive matching
library(stringdist)
lexops |>
 split_by(VAL.Warriner, 1:3 ~ 4.5:5.5 ~ 7:9) |>
 control_for(Rhyme.eSpeak.br) |>
 control_for_map(stringdist, eSpeak.br_1letter, 0:2, method="lv") |>
 generate(10, match_null = "inclusive")


Get a box type's colour

Description

Simple function for getting the visualisation colour (in hex) for different coloured boxes. Colours are only accurate for the LexOPS shiny app.

Usage

get_box_colour(box_type)

Arguments

box_type

A character vector (one of: "primary", "warning", "Success", "danger", and "info"), specifying which kind of box to generate the colour for.

Value

A character vector of the colour's hex value.


Check whether an object is of class LexOPS_pipeline

Description

Check whether an object is of class LexOPS_pipeline

Usage

is.LexOPS_pipeline(x)

Arguments

x

Object, possibly resulting from one of split_by, control_for, etc..

Value

A logical value: TRUE if x is of class LexOPS_pipeline, or FALSE otherwise.

Examples


library(lexopsdata)

# the lexops dataset is not a LexOPS_pipeline before going through split_by() or control_for()
is.LexOPS_pipeline(lexops)  # FALSE

# a pipeline pregeneration is a LexOPS_pipeline
pregen <- lexops |>
  subset(PK.Brysbaert >= .75) |>
  split_by(BG.SUBTLEX_UK, 0.001:0.003 ~ 0.009:0.011) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length, 0:0)

is.LexOPS_pipeline(pregen)  # TRUE

# a pipeline's output is still a LexOPS_pipeline after going through generate()
postgen <- generate(pregen, 10)
is.LexOPS_pipeline(postgen)  # TRUE


The lexops dataset

Description

A data frame containing 68 variables for words, in English. This dataset was originally stored in the LexOPS package, but is now installed separately via lexopsdata (lexops).

Usage

lexops

Value

The data.frame object containing the lexops dataset.

Examples

lexops


Convert to long format

Description

Converts the generated stimuli from the generate function into long format.

Usage

long_format(df, include = "design", include_candids = FALSE)

Arguments

df

A data frame that is the result from control_for or split_by.

include

A string indicating whether the long-format result should include all variables in the original data frame ("all"), only those specified by split_by and control_for ("design"), only those specified in split_by ("splits"), or only those specified by control_for ("controls"). Set to NA for only the data in the wide-format data frame. The default is "design".

include_candids

Logical; whether to include data about unused candidates in the result. If TRUE, will store whether each word was actually used in column, is_stim. Default is FALSE.

Value

The generated stimuli, as a data.frame object in long format, containing requested variables from the original df, and the variables of item_nr, condition, euclidean_distance (from the match_null).

Examples



library(lexopsdata)

lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6 ~ 7:20) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  generate(n = 20) |>
  long_format(include = "all")


Get suitable matches for a single item on one or several dimensions.

Description

Suggests items that are suitable matches for a target item, based on selected variables of a data frame. Note that unlike functions in the generate pipeline (e.g. control_for), multiple variables' tolerances can be defined in one function.

Usage

match_item(
  df = LexOPS::lexops,
  target,
  ...,
  id_col = "string",
  filter = TRUE,
  standard_eval = FALSE
)

Arguments

df

A data frame to reorder, containing the target string (default = lexops).

target

The target string

...

Should specify the variables and tolerances in the form ⁠Length = 0:0, Zipf.SUBTLEX_UK = -0.1:0.1, PoS.SUBTLEX_UK⁠. Numeric variables can include tolerances (as elements 2:3 of a vector). Numeric variables with no tolerances will be matched exactly.

id_col

A character vector specifying the column identifying unique observations (e.g. in lexopsdata::lexops, the id_col is "string").

filter

Logical. If TRUE, matches outside the tolerances specified in vars are removed. If FALSE, a new column, matchFilter is calculated indicating whether or not the string is within all variables' tolerances. (Default = TRUE.)

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R object of list. If TRUE, ... should be a single list specifying the variables to match by and their tolerances, in the form list("numericVariable1Name", c("numericVariable2Name", -1.5, 3), "characterVariableName"). Default = FALSE.

Value

An object of class data.frame derived from df. If filter == TRUE, will only contain matches. If filter == FALSE, will be the original df object, with a new column, "matchFilter".

See Also

lexops for the default data frame and associated variables.

Examples



library(lexopsdata)

# Match by number of syllables exactly
match_item(lexops, "thicket", Syllables.CMU)

# Match by number of syllables exactly, but keep all entries in the original dataframe
match_item(lexops, "thicket", Syllables.CMU, filter = FALSE)

# Match by number of syllables exactly, and rhyme
match_item(lexops, "thicket", Syllables.CMU, Rhyme.CMU)

# Match by length exactly, and closely by frequency (within 0.2 Zipf either way)
match_item(lexops, "thicket", Length, Zipf.SUBTLEX_UK = -0.2:0.2)

# The syntax supports matching by multiple variables
match_item(
  lexops,
  "elephant",
  BG.SUBTLEX_UK = -0.005:0.005,
  Length = 0:0,
  Zipf.SUBTLEX_UK = -0.1:0.1,
  PoS.SUBTLEX_UK,
  RT.ELP = -10:10
)

# Match using standard evaluation
match_item(
  lexops,
  "thicket",
  list("Length", c("Zipf.SUBTLEX_UK", -0.2, 0.2)),
  standard_eval = TRUE
)

# Find matches within an orthographic levenshtein distance of 5 from "thicket":
library(dplyr)
library(stringdist)
targ_word <- "thicket"
lexops |>
  mutate(old = stringdist(targ_word, string, method="lv")) |>
  match_item(targ_word, old = 0:5)

# Find matches within a phonological levenshtein distance of 2 from "thicket":
# (note that this method requires 1-letter phonological transcriptions)
library(dplyr)
library(stringdist)
targ_word <- "thicket"
targ_word_pronun <- lexops |>
  filter(string == "thicket") |>
  pull(eSpeak.br_1letter)
lexops |>
  mutate(pld = stringdist(targ_word_pronun, eSpeak.br_1letter, method="lv")) |>
  match_item(targ_word, pld = 0:2)


An outdated wrapper for match_item

Description

The match_word() function has been replaced by match_item. This wrapper for the function has been kept to support backwards compatibility to code written in older versions of LexOPS. This wrapper may be removed in the future, so please update your code to use match_item.

Usage

match_word(
  df = LexOPS::lexops,
  target,
  ...,
  id_col = "string",
  filter = TRUE,
  standard_eval = FALSE
)

Arguments

df

A data frame to reorder, containing the target string (default = lexopsdata::lexops).

target

The target string

...

Should specify the variables and tolerances in the form ⁠Length = 0:0, Zipf.SUBTLEX_UK = -0.1:0.1, PoS.SUBTLEX_UK⁠. Numeric variables can include tolerances (as elements 2:3 of a vector). Numeric variables with no tolerances will be matched exactly.

id_col

A character vector specifying the column identifying unique observations (e.g. in lexopsdata::lexops, the id_col is "string").

filter

Logical. If TRUE, matches outside the tolerances specified in vars are removed. If FALSE, a new column, matchFilter is calculated indicating whether or not the string is within all variables' tolerances. (Default = TRUE.)

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R object of list. If TRUE, ... should be a single list specifying the variables to match by and their tolerances, in the form list("numericVariable1Name", c("numericVariable2Name", -1.5, 3), "characterVariableName"). Default = FALSE.

Value

An object of class data.frame derived from df. If filter == TRUE, will only contain matches. If filter == FALSE, will be the original df object, with a new column, "matchFilter".

See Also

lexops for the default data frame and associated variables.

Examples



library(lexopsdata)

# Match by number of syllables exactly
match_word(lexops, "thicket", Syllables.CMU)

# Match by number of syllables exactly, but keep all entries in the original dataframe
match_word(lexops, "thicket", Syllables.CMU, filter = FALSE)

# Match by number of syllables exactly, and rhyme
match_word(lexops, "thicket", Syllables.CMU, Rhyme.CMU)

# Match by length exactly, and closely by frequency (within 0.2 Zipf either way)
match_word(lexops, "thicket", Length, Zipf.SUBTLEX_UK = -0.2:0.2)

# The syntax supports matching by multiple variables
match_word(
  lexops,
  "elephant",
  BG.SUBTLEX_UK = -0.005:0.005,
  Length = 0:0,
  Zipf.SUBTLEX_UK = -0.1:0.1,
  PoS.SUBTLEX_UK,
  RT.ELP = -10:10
)

# Match using standard evaluation
match_word(
  lexops,
  "thicket",
  list("Length", c("Zipf.SUBTLEX_UK", -0.2, 0.2)),
  standard_eval = TRUE
)

# Find matches within an orthographic levenshtein distance of 5 from "thicket":
library(dplyr)
library(stringdist)
targ_word <- "thicket"
lexops |>
  mutate(old = stringdist(targ_word, string, method="lv")) |>
  match_word(targ_word, old = 0:5)

# Find matches within a phonological levenshtein distance of 2 from "thicket":
# (note that this method requires 1-letter phonological transcriptions)
library(dplyr)
library(stringdist)
targ_word <- "thicket"
targ_word_pronun <- lexops |>
  filter(string == "thicket") |>
  pull(eSpeak.br_1letter)
lexops |>
  mutate(pld = stringdist(targ_word_pronun, eSpeak.br_1letter, method="lv")) |>
  match_word(targ_word, pld = 0:2)


A non-standard evaluation parser for ellipses

Description

This is useful for specifying multiple parameters in non-standard evaluation for match_item().

Usage

parse_ellipsis(...)

Arguments

...

Variables and tolerances, in the form ⁠num_variable1 = -1:3, num_variable2 = -0.5:0.5, char_variable1⁠. Variables and tolerances should be separated by a =, and lower and upper boundaries of tolerances should be separated by :. Variables without tolerances are also supported (useful for character variables or matching by numeric variables exactly, i.e. shorthand for 0:0).

Value

A list object in the form list(c("num_variable1", -1, 3), c("num_variable2", -0.5, 0.5), "char_variable1").

Examples


parse_ellipsis(substitute(c(Length = 0:0, Zipf.SUBTLEX_UK = -0.1:0.1, PoS.SUBTLEX_UK)))

parse_ellipsis(substitute(c(Length = 0:0,
                           Zipf.SUBTLEX_UK = -0.1:0.1,
                           PoS.SUBTLEX_UK,
                           BG.SUBTLEX_UK = -0.005:0.005)))


A non-standard evaluation parser for levels (e.g., for split_by())

Description

A non-standard evaluation parser for levels (e.g., for split_by())

Usage

parse_levels(var, levels = NA)

Arguments

var

A column name (non-standard evaluation).

levels

Levels in the form of tilde-separated vectors (e.g. c("noun", "name") ~ c("verb", "adjective")) or character vectors (e.g. "noun" ~ "verb"). Numeric levels can be in the form 1.5:2.75 ~ 3.5:4.75.

Value

A list object in the form list("column_name", c(1, 2), c(3, 4), c(5, 6)).

Examples


# Numeric sections of a distribution can be specified as lower:upper bound...

parse_levels(substitute(Zipf.SUBTLEX_UK), substitute(1:2 ~ 3:4 ~ 5:6))

# ...or c(lower, upper)

parse_levels(substitute(Zipf.SUBTLEX_UK), substitute(c(1, 2) ~ c(3, 4) ~ c(5, 6)))

# Can give any level as just `NULL` or `NA` to store the level as `NA`
# (e.g. for `split_by_map()` function in future)

parse_levels(substitute(example_variable), substitute(NULL ~ 1.2:4 ~ 5.2:6))
parse_levels(substitute(example_variable), substitute(NA ~ 1.2:4 ~ 5.2:6))

# Non-numeric categories can be specified like so

parse_levels(substitute(PoS.SUBTLEX_UK), substitute("noun" ~ "verb"))

parse_levels(substitute(PoS.SUBTLEX_UK), substitute(c("noun", "name") ~ c("adjective", "verb")))

# Can give no value for `levels` (i.e. `levels` is `NA`),
# e.g. when matching exactly, or categorically

parse_levels(substitute(PoS.SUBTLEX_UK))

# Can give vector of variables in non-standard eval

parse_levels(substitute(c(Zipf.SUBTLEX_UK, Length)), substitute(0:2.5))
parse_levels(substitute(c(Zipf.SUBTLEX_UK, Length)))


A parse for extracting contents of c() in a character vector representation.

Description

A parse for extracting contents of c() in a character vector representation.

Usage

parse_unvectorise(vec_str)

Arguments

vec_str

The character vector (string), e.g., c(value1, value2, value3)

Value

A parsed, unvectorised character vector.


Plot the generated stimuli's design

Description

Takes the output from generate or long_format, and plots conditions' distributions on numeric variables used in the generate pipeline (i.e. indepdent variables, controls). Alternatively, distributions of any numeric variables in the original dataframe can be queried.

Usage

plot_design(
  df,
  include = "design",
  dodge_width = 0.1,
  point_size = 0.5,
  line_width = 1,
  force = TRUE,
  id_col = "string"
)

Arguments

df

Output from generate or long_format

include

A character vector indicating which variables to include in the plot. This can be those specified by split_by and control_for ("design"), only those specified in split_by ("splits"), or only those specified by control_for ("controls"). Alternatively, this can be a character vector of the variables that should be plotted, that were in the original dataframe. Default is "design".

dodge_width

The width to give to ggplot2::position_dodge (default is 0.2)

point_size

Size of points (default = 0.75)

line_width

Thickness of lines (default = 1)

force

Logical, should the function be forced to try and work if attributes are missing (default is TRUE)? If TRUE, will expect the dataframe to have a structure similar to that produced by long_format, where condition is character or factor, and item_nr is numeric or factor. Other variables will be plot-able if given to the include argument.

id_col

A character vector specifying the column identifying unique observations (e.g. in lexops, the id_col is "string"). Ignored unless force=TRUE, in which case it is required.

Value

A ggplot2 object visualising how conditions differ in independent variables, and are matched for in controls.

Examples



library(lexopsdata)

stim <- lexops |>
  dplyr::filter(PK.Brysbaert >= .75) |>
  split_by(BG.SUBTLEX_UK, 0.001:0.003 ~ 0.009:0.011) |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length) |>
  generate(n = 50, match_null = "balanced")
plot_design(stim)


Plot the cumulative frequency of stimuli generated

Description

Plots iterations by number of items generated, when given a dataframe which has been passed through generate.

Usage

plot_iterations(df, line_width = 1)

Arguments

df

Output from generate or long_format

line_width

Thickness of lines (default = 1)

Value

A ggplot2 object visualising how conditions differ in independent variables, and are matched for in controls.

Examples



library(lexopsdata)

stim <- lexops |>
  dplyr::filter(PK.Brysbaert >= .75) |>
  split_by(BG.SUBTLEX_UK, 0.001:0.003 ~ 0.009:0.011) |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length) |>
  generate(n = 50, match_null = "balanced")
plot_iterations(stim)


Plot how well the stimuli represent the underlying population of words given

Description

Takes the output from generate() or long_format(), and plots distributions on numeric variables used in the generate pipeline (i.e. indepdent variables, controls), collapsed across conditions, relative to the underlying distribution. Alternatively, distributions of any specific numeric variables in the original dataframe can be queried.

Usage

plot_sample(df, include = "design", force = TRUE, id_col = "string")

Arguments

df

Output from generate() or long_format()

include

A character vector indicating which variables to include in the plot. This can be those specified by split_by() and control_for() ("design"), only those specified in split_by() ("splits"), or only those specified by control_for() ("controls"). Alternatively, this can be a character vector of the variables that should be plotted, that were in the original dataframe. Default is "design".

force

Logical, should the function be forced to try and work if attributes are missing (default is TRUE)? If TRUE, will expect the dataframe to have a structure similar to that produced by long_format(), where condition is character or factor, and item_nr is numeric or factor. Other variables will be plot-able if given to the include argument.

id_col

A character vector specifying the column identifying unique observations (e.g. in lexopsdata::lexops, the id_col is "string"). Ignored unless force=TRUE, in which case it is required.

Value

A ggplot2 object showing how conditions differ in independent variables, and are matched for in controls.

Examples


library(lexopsdata)

stim <- lexops |>
  dplyr::filter(PK.Brysbaert >= .75) |>
  split_by(PoS.SUBTLEX_UK, "noun" ~ "adjective" ~ "verb") |>
  split_by(CNC.Brysbaert, 1:2 ~ 4:5) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length, 0:0) |>
  generate(n = 50, match_null = "balanced")
plot_sample(stim)


Prepend a Vector

Description

Copied from old versions of rlang as function now deprecated.

Usage

prepend(x, values, before = 1)

Arguments

x

the vector to be modified.

values

to be included in the modified vector.

before

a subscript, before which the values are to be appended.

Value

A merged vector.


Prepend a List

Description

A prepend function that plays nicely with lists.

Usage

prepend_list(x, ...)

Arguments

x

the vector to be modified.

...

the objects to be included in the modified vector.

Value

A merged vector.


Print a summary about an ungenerated LexOPS pipeline

Description

Prints a summary about a LexOPS pipeline object (returned from functions like split_by, control_for, etc.), listing the splits and controls in the pipeline so far.

Usage

## S3 method for class 'LexOPS_pipeline'
print(x, ...)

Arguments

x

A LexOPS_pipeline object resulting from one of split_by, control_for, etc., which has not yet been passed through generate.

...

Other arguments passed to or from other methods (unused).

Value

No return value, called for side effects (printing).

Examples


library(lexopsdata)

pipeline <- lexops |>
  subset(PK.Brysbaert >= .75) |>
  split_by(BG.SUBTLEX_UK, 0.001:0.003 ~ 0.009:0.011) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  control_for(Length, 0:0)

pipeline



Run the LeXOPS shiny App

Description

Runs the LexOPS shiny App, with optional additional arguments.

Usage

run_shiny(...)

Arguments

...

optional arguments to shiny::runApp

Details

The LexOPS shiny app requires additional packages. If any dependencies are missing, the user will be prompted to install them. The additional packages required are:

Value

No return value, called to initialise the LexOPS shiny app.

Examples

if (interactive()) { run_shiny() }


Get sensible slider values

Description

Function for converting a numeric vector into recommended arguments for shiny::sliderInput, for sliders in LexOPS.

Usage

sensible_slider_vals(numeric_vec, n_levels, is_tolerance = FALSE)

Arguments

numeric_vec

The numeric vector which the slider will be for.

n_levels

How many sliders are to be generated for this variable?

is_tolerance

Logical; is the slider for specifying tolerances (e.g. for matching)? Default is FALSE.

Value

A list object, containing the following recommended argument values for shiny::sliderInput:


Set options for generating stimuli.

Description

When the first function called in a generate pipeline, allows the user to set options that will be passed to all subsequent functions in the pipeline.

Usage

set_options(df, id_col = "string", cond_col = "LexOPS_splitCond")

Arguments

df

The dataframe that will be used in the generate pipeline.

id_col

A character vector specifying the column identifying unique observations (e.g. in lexops, the id_col is "string"). If the id_col is not found in df, LexOPS will use row numbers.

cond_col

Prefix with which to name the columns where conditions will be stored (default = "LexOPS_splitCond"). Each time split_by is run on a dataframe, a new cond_col is added to the data frame, e.g., the first time will add splitCond_A, the second time will add split_cond_B, etc. The default is usually sufficient.

Value

An object of class LexOPS_pipeline, containing dataframe df, with the options stored in the attributes.

Examples



library(lexopsdata)

# give a df with "word" as the identifying column
lexops |>
  dplyr::rename(word = string) |>
  # tell LexOPS that "word" is the identifying column
  set_options(id_col = "word") |>
  split_by(Syllables.CMU, 1:3 ~ 4:6 ~ 7:20) |>
  control_for(Zipf.SUBTLEX_UK, -0.2:0.2) |>
  generate(n = 20)


Add a split to the data.

Description

Specifies splits for one IV for a factorial design. Can be called multiple times for multiple splits.

Usage

split_by(x, var, levels, filter = TRUE, standard_eval = FALSE)

Arguments

x

A data frame containing the IV and strings, or a LexOPS_pipeline object resulting from one of split_by, control_for, etc..

var

The column to treat as an independent variable (non-standard evaluation).

levels

The boundaries to use as levels of this variable (non-standard evaluation). These should be specified in the form 1:3 ~ 4:6 ~ 7:9 or c(1, 3) ~ c(4, 6) ~ c(7, 9) for numeric variables, and (e.g.) ⁠"noun" ~ "verb" ~ c"adjective"⁠ for character variables, where levels are separated by the ~ operator. Levels must be non-overlapping.

filter

Logical. If TRUE, words which fit no conditions are removed.

standard_eval

Logical; bypasses non-standard evaluation, and allows more standard R objects in var and levels. If TRUE, var should be a character vector referring to a column in df (e.g. "Zipf.SUBTLEX_UK"), and levels should be a list containing multiple vectors of length 2, each specifying the boundaries of one level's bin (e.g. list(c(1, 3), c(4, 6), c(7, 20))). Default = FALSE.

Value

A LexOPS_pipeline object, where df has a new column (name defined by cond_col argument of set_options()) identifying which level of the IV each item belongs to.

See Also

lexops for the default data frame and associated variables.

Examples


library(lexopsdata)

# Create 3 levels of syllables, for 1-3, 4-6, and 7-20 syllables
lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6 ~ 7:20)

# Same split as above, but supplying boundaries as vectors
lexops |>
  split_by(Syllables.CMU, c(1, 3) ~ c(4, 6) ~ c(7, 20))

# Create 2 levels of position of speech, noun and verb
lexops |>
  split_by(PoS.SUBTLEX_UK, "noun" ~ "verb")

# split into two levels: (1) nouns or names, and (2) adjectives or adverbs
lexops |>
 split_by(PoS.SUBTLEX_UK, c("noun", "name") ~ c("adjective", "adverb"))

# Perform two splits
lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6 ~ 7:20) |>
  split_by(PoS.SUBTLEX_UK, c("noun", "name") ~ c("adjective", "adverb"))

# Bypass non-standard evaluation
lexops |>
  split_by("Syllables.CMU", list(c(1, 3), c(4, 6), c(7, 20)), standard_eval = TRUE) |>
  split_by("PoS.SUBTLEX_UK", list(c("noun", "name"), "verb"), standard_eval = TRUE)


Add a random split to the data.

Description

Adds a split to the data comparable to that made by split_by, but split randomly through the data. All entries in df of the resulting LexOPS_pipeline object are assigned a level randomly.

Usage

split_random(x, nlevels = 2, seed = NA, equal_size = FALSE)

Arguments

x

A data frame containing the IV and strings, or a LexOPS_pipeline object resulting from one of split_by, control_for, etc..

nlevels

An integer, specifying how many levels this random split should have (default = 2).

seed

Deprecated: set seeds externally instead (e.g., set.seed()).

equal_size

Logical; should LexOPS create equal (or as close to equal as possible) numbers of candidates for each level? When FALSE, will sample N levels with replacement, when TRUE will sample N rows. Setting to TRUE is recommended, as it will generally create more candidate matches. Default is FALSE to avoid altering reproducibility of existing pipelines.

Value

A LexOPS_pipeline object, where df has a new column (name defined by cond_col argument) identifying which level of the randomly generated IV each item belongs to.

Examples



library(lexopsdata)

# 2 (syllables: few, many) by 2 (random: level 1, level 2) design
lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6) |>
  split_random(nlevels = 2, equal_size = TRUE)


Convert a variable name to its measure

Description

Converts the name of a variable from lexops (e.g. "fpmw.SUBTLEX_US") into the name of its measure (e.g. "frequency per million words").

Usage

var_to_measure(
  var,
  first_cite = TRUE,
  default = "",
  title_caps = FALSE,
  include_pronunciations = TRUE,
  standard_eval = FALSE
)

Arguments

var

The variable name (non-standard evaluation)

first_cite

Logical; if TRUE, gives full name (e.g. frequency per million words), if FALSE, gives abbreviated name (e.g. FPMW)

default

The character string that should be returned if the variable does not have a known cietable source

title_caps

Logical; use title capitalisation (e.g. "Familiarity Ratings" rather than "famliarity ratings"). Default is FALSE.

include_pronunciations

Logical; allow pronunciation transpositions as measures (e.g. CMU.1letter). Default is TRUE.

standard_eval

Logical; bypasses non-standard evaluation. If TRUE, var should be a column name in quotation marks. If FALSE, the quotation marks are not necessary. Default = FALSE.

Value

A citation of a variable's source in APA format. Returns default if not recognised as a citeabile source.

Examples


var_to_measure(Zipf.SUBTLEX_UK)

var_to_measure("AROU.Glasgow_Norms", standard_eval = TRUE)

var_to_measure(AoA.Kuperman, first_cite = FALSE)


Convert a variable name to APA citation

Description

Converts the name of a variable from lexops (e.g. "Zipf.SUBTLEX_US") into an APA-style citation (e.g. "SUBTLEX-US (Brysbaert & New, 2009)").

Usage

var_to_source(var, first_cite = TRUE, default = "", standard_eval = FALSE)

Arguments

var

The variable name (non-standard evaluation)

first_cite

Logical; if TRUE, gives full citation, if FALSE, gives abbreviated (i.e. "et al.") citation

default

The character string that should be returned if the variable does not have a known citeable source

standard_eval

Logical; bypasses non-standard evaluation. If TRUE, var should be a column name in quotation marks. If FALSE, the quotation marks are not necessary. Default = FALSE.

Value

A citation of a variable's source in APA format. Returns default if not recognised as a citeable source.

Examples


var_to_source(Zipf.SUBTLEX_UK)

var_to_source("AROU.Glasgow_Norms", standard_eval = TRUE)

var_to_source(AoA.Kuperman, first_cite = FALSE)


Convert a variable name to a url reference.

Description

Converts the name of a variable from lexops (e.g. "Zipf.SUBTLEX_US") into a url (usually doi).

Usage

var_to_url(var, default = "", standard_eval = FALSE)

Arguments

var

The variable name (non-standard evaluation)

default

The character string that should be returned if the variable does not have a known citeable source

standard_eval

Logical; bypasses non-standard evaluation. If TRUE, var should be a column name in quotation marks. If FALSE, the quotation marks are not necessary. Default = FALSE.

Value

A citation of a variable's source in APA format. Returns default if not recognised as a citeabile source.

Examples


var_to_url(Zipf.SUBTLEX_UK)

var_to_url("AROU.Glasgow_Norms", standard_eval = TRUE)

var_to_url(AoA.Kuperman)