Package 'zutils'

Title: Zhang Liang's miscellaneous utilities
Description: This package mainly contains some miscellaneous utilities that I use frequently.
Authors: Liang Zhang [aut, cre]
Maintainer: Liang Zhang <[email protected]>
License: MIT + file LICENSE
Version: 0.0.10
Built: 2024-11-21 03:04:07 UTC
Source: https://github.com/psychelzh/zutils

Help Index


Create a call to a function with its arguments

Description

This is basically a wrapper around rlang::call2() that allows you to extract the arguments from a function and pass them to rlang::call2() without having to type them out.

Usage

call_full(.fn, ...)

Arguments

.fn

The function to call.

...

Arguments to pass to the function.

Value

A call to the function with its arguments.


Cautiously evaluate an expression

Description

This function is useful for when you want to evaluate an expression, but you want to catch any errors and return a default value instead. Note the error message will be printed as a warning as the name of the function suggests.

Usage

cautiously(.f, otherwise = NULL)

Arguments

.f

A function to modify. See as_function() for details.

otherwise

A value to return if the expression throws an error.

Value

A function that evaluates the expression and returns the result or the default value if an error is thrown.


Tidy select for list

Description

A tidy select interface for lists. See tidyselect::eval_select() for details.

Usage

select_list(.l, ...)

Arguments

.l

A list() object.

...

One or more unquoted expressions separated by commas.

Value

A list with the selected elements.


Separate a column into multiple columns

Description

This is a wrapper around tidyr::separate_wider_regex() that allows to split a column into multiple columns. The column contains so-called delimiter separated values (DSV) and the values are extracted using regular expressions.

Usage

separate_wider_dsv(
  data,
  col,
  names,
  ...,
  patterns = NULL,
  delim = "_",
  prefix = NULL,
  suffix = NULL
)

Arguments

data

A data frame.

col

<tidy-select> Column to separate.

names

Names of the new columns. Use NA if you want a component not to be in the output.

...

Additional arguments passed to tidyr::separate_wider_regex().

patterns

Regular expressions to extract the values from the column. If NULL, the pattern will match any character non-greedily. The length of the vector must be equal to the number of new columns.

delim

Delimiter used in the column to separate different pieces of values.

prefix, suffix

Prefix and suffix to be removed from the target column to retrieve the values.

Value

A data frame with the separated columns.