matsindf_apply_types: Determine types of '.dat' and '...' arguments for...

View source: R/matsindf_apply.R

matsindf_apply_typesR Documentation

Determine types of .dat and ... arguments for matsindf_apply()

Description

This is a convenience function that returns a list for the types of .dat and ... as well as names in .dat and ..., with components named .dat_null, .dat_df, .dat_list, .dat_names, FUN_arg_all_names, FUN_arg_default_names, FUN_arg_default_values, dots_present, all_dots_num, all_dots_mats, all_dots_list, all_dots_vect, all_dots_char, all_dots_longer_than_1, dots_names, and keep_args.

Usage

matsindf_apply_types(.dat = NULL, FUN, ..., .warn_missing_FUN_args = TRUE)

Arguments

.dat

The .dat argument to be checked.

FUN

The function sent to matsindf_apply().

...

The list of arguments to matsindf_apply() to be checked.

.warn_missing_FUN_args

A boolean that tells whether to warn of missing arguments to FUN. Default is TRUE.

Details

When .dat is a data.frame, both .dat_list and .dat_df are TRUE.

When arguments are present in ..., dots_present is TRUE but FALSE otherwise. When all items in ... are single numbers, all_dots_num is TRUE and all other list members are FALSE. When all items in ... are matrices, all_dots_mats is TRUE and all other list members are FALSE. When all items in ... are lists, all_dots_list is TRUE and all other list members are FALSE. When all items in ... are vectors (including lists), all_dots_vect is TRUE. When all items in ... have length > 1, all_dots_longer_than_1 is TRUE. When all items in ... are character strings, all_dots_char is TRUE and all other list members are FALSE.

The various ⁠FUN_arg_*⁠ components give information about the arguments to FUN. FUN_arg_all_names gives the names of all arguments to FUN, regardless of whether they have default values. FUN_arg_default_names gives the names of only those arguments with default values. FUN_arg_default_values gives the values of the default arguments, already eval()ed in the global environment. When there are no values in a category, NULL is returned. thus, if FUN has no arguments with default values assigned in the signature of the function, both FUN_arg_default_names and FUN_arg_default_values will be NULL. If FUN has no arguments, all of FUN_arg_all_names, FUN_arg_default_names and FUN_arg_default_values will be NULL.

keep_args is a named list() of arguments, which indicates which arguments to keep from which source (..., .dat, or default args to FUN) by order of preference, ... over .dat over default arguments to FUN. Arguments not used by FUN are kept, again according to the rules of preference.

Value

A logical list with components named .dat_null, .dat_df, .dat_list, .dat_names, FUN_arg_all_names, FUN_arg_default_names, FUN_arg_default_values, dots_present, all_dots_num, all_dots_mats, all_dots_list, all_dots_vect, all_dots_char, all_dots_longer_than_1, dots_names, and keep_args.

Examples

identity_fun <- function(a, b) {list(a = a, b = b)}
matsindf_apply_types(.dat = NULL, FUN = identity_fun, a = 1, b = 2)
matsindf_apply_types(.dat = data.frame(), FUN = identity_fun,
                     a = matrix(c(1, 2)), b = matrix(c(2, 3)))
matsindf_apply_types(.dat = list(), FUN = identity_fun,
                     a = c(1, 2), b = c(3, 4))
matsindf_apply_types(.dat = NULL, FUN = identity_fun,
                     a = list(1, 2), b = list(3, 4))

matsindf documentation built on Aug. 18, 2023, 5:06 p.m.