Package 'mamisc'

Title: Miscellaneous Functions by Paul Hoffman
Description: More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description.
Authors: Paul Hoffman [aut, cre]
Maintainer: Paul Hoffman <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9001
Built: 2024-11-11 02:58:07 UTC
Source: https://github.com/mojaveazure/mamisc

Help Index


mamisc: Miscellaneous Functions by Paul Hoffman

Description

More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description.

Author(s)

Maintainer: Paul Hoffman [email protected] (ORCID)

See Also

Useful links:


Create Abbreviations

Description

Create Abbreviations

Usage

abbrv(x, digits = TRUE)

Arguments

x

A character vector

digits

Include digits in the abbreviation

Value

Abbreviated versions of x

Examples

abbrv(c('HelloWorld', 'LetsGo3', 'tomato'))
abbrv(c('HelloWorld', 'LetsGo3', 'tomato'), digits = FALSE)
abbrv('Wow3', digits = FALSE)

Blend two or more colors together

Description

Blend two or more colors together

Usage

blend_colors(..., as.rgb = FALSE)

Arguments

...

Two or more colors to blend together; these can be in a vector or standalone

as.rgb

Return in RGB form, otherwise return in hexadecimal form

Value

The blended color in RGB form (1 x 3 matrix) or hexadecimal form

See Also

Other color_theory: col2hex(), contrast-theory, text_color()

Examples

blend_colors('red', 'green')
if (requireNamespace('scales', quietly = TRUE)) {
  scales::show_col(c('red', blend_colors('red', 'green'), 'green'), ncol = 3)
}

Convert R colors to hexadecimal

Description

Convert R colors to hexadecimal

Usage

col2hex(...)

Arguments

...

R colors

Value

The hexadecimal representations of input colors

See Also

Other color_theory: blend_colors(), contrast-theory, text_color()

Examples

col2hex('black', 'red', 'grey')

Color Intensity

Description

Get the intensity and/or luminance of a color

Usage

intensity(color)

luminance(color)

Arguments

color

A vector of colors

Value

A vector of intensities/luminances for each color

Source

https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color

See Also

Other color_theory: blend_colors(), col2hex(), text_color()

Examples

intensity(color = c('black', 'white', '#E76BF3'))

luminance(color = c('black', 'white', '#E76BF3'))

Interleave vectors together

Description

Interleave vectors together

Usage

interleave(...)

Arguments

...

Vectors to be interleaved

Value

A vector with the values from each vector in ... interleaved


Is an Object a Data Frame

Description

Is an Object a Data Frame

Usage

is_data_frame(x)

is_bare_data_frame(x)

Arguments

x

An object

Value

TRUE if x is a data frame, otherwise FALSE


Is a List Named

Description

Is a List Named

Usage

is_named_list(x, pass.zero = FALSE)

Arguments

x

A list

pass.zero

Return TRUE for zero-length lists

Value

...


Vectorized Testing of NULL

Description

Vectorized Testing of NULL

Usage

is_nullv(x)

Arguments

x

A list-like object

Value

...


Hide Shiny Tabs with ShinyJS

Description

Hide Shiny Tabs with ShinyJS

Usage

js_tab_hide(id, values, fxn = "hide")

Arguments

id

ID of a tabsetPanel

values

One or more values of a tabPanel (see the value parameter)

fxn

Name of JavaScript call function

Value

A string with a JavaScript function to hide a set of tabs

Note

This function is designed to run custom JavaScript code using shinyjs::extendShinyJS(); use of custom JavaScript code requires the V8 package. V8 requires a local install of either the V8 JavaScript Engine or Node.js

See Also

shinyjs::extendShinyJS() shiny::tabPanel()

Other shiny: js_tab_key()

Other shinyjs: js_tab_key()


Get JavaScript IDs for Shiny Tabs

Description

Get JavaScript IDs for Shiny Tabs

Usage

js_tab_key(id, values)

Arguments

id

ID of a tabsetPanel

values

One or more values of a tabPanel (see the value parameter)

Value

A string with the JavaScript ID for a given set of tabs

See Also

shiny::tabsetPanel() shiny::tabPanel()

Other shiny: js_tab_hide()

Other shinyjs: js_tab_hide()


Is a Resource Online and Available

Description

Check to see if a given resource is online and accessible over the internet

Usage

online(uri, strict = FALSE, timeout = getOption(x = "timeout"))

Arguments

uri

The URI of a given resource

strict

Ensures the HTTP status code is 200

timeout

Timeout in seconds; defaults to the option “timeout” (currently set to 60 seconds)

Value

TRUE if uri is accessible, otherwise FALSE

Note

This function requires the \href{https://cran.r-project.org/package=httr}{\pkg{httr}} package to be installed


Keyed Ordering Permutation

Description

Keyed Ordering Permutation

Usage

order2(
  ...,
  key = identity,
  na.last = TRUE,
  decreasing = FALSE,
  method = c("auto", "shell", "radix")
)

Arguments

...

a sequence of numeric, complex, character or logical vectors, all of the same length, or a classed R object.

key

A function that takes a single argument, defaults to identity

na.last

for controlling the treatment of NAs. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed (see ‘Note’.)

decreasing

logical. Should the sort order be increasing or decreasing? For the "radix" method, this can be a vector of length equal to the number of arguments in ... and the elements are recycled as necessary. For the other methods, it must be length one.

method

the method to be used: partial matches are allowed. The default ("auto") implies "radix" for numeric vectors, integer vectors, logical vectors and factors with fewer than 2312^{31} elements. Otherwise, it implies "shell". For details of methods "shell", "quick", and "radix", see the help for sort.

Value

An integer vector with the ordered indices of the input data

See Also

sorted base::sort base::order


Create a List with a Serial Comma

Description

Create a List with a Serial Comma

Usage

oxford(
  ...,
  cnj = c("or", "and"),
  quote = c("single", "double", "none"),
  fancy = getOption(x = "useFancyQuotes", default = TRUE)
)

Arguments

...

A character vector to join

cnj

Conjunction to use for final entry

quote

Quote the entries of ...; choose from:

  • single”: single quotes

  • double”: double quotes

  • none”: no extra quoting

fancy

Use fancy quotes; defaults to the value of the “useFancyQuotes” option (currently set to TRUE)

Value

... arranged into an English list with a serial comma when needed

See Also

sQuote() dQuote()

Examples

oxford('cell')
oxford('cell', 'ident')
oxford('cell', 'ident', 'gene')

Generate a powerset

Description

Generate a powerset

Usage

powerset(x)

Arguments

x

A list or vector of values to generate all possible combinations of

Value

A list with all possible combinations of x

Examples

powerset(x = 1:3)
powerset(x = letters[1:3])

Rdocumentation Itemized List

Description

Generate an Rdocumentation itemized list

Usage

rd_ilist(x)

Arguments

x

A vector of values for the list

Value

An Rdocumentation itemized list suitable for injecting into documentation files with \Sexpr

See Also

Other roxygen: rd_required_pkgs()

Examples

#' \Sexpr[results=rd]{odds::rd_ilist()}

Rdocumentation Note of Required Packages

Description

Rdocumentation Note of Required Packages

Usage

rd_required_pkgs(x, multiple = FALSE)

Arguments

x

A vector of package names

multiple

...

Value

...

See Also

Other roxygen: rd_ilist()

Examples

#' \Sexpr[results=rd]{odds::rd_required_pkgs()}

Sort With A Key

Description

Sort With A Key

Usage

sorted(x, key = identity, decreasing = FALSE, ...)

## Default S3 method:
sorted(x, key = identity, decreasing = FALSE, na.last = NA, ...)

Arguments

x

for sort an R object with a class or a numeric, complex, character or logical vector. For sort.int, a numeric, complex, character or logical vector, or a factor.

key

A function that takes a single argument, defaults to identity

decreasing

logical. Should the sort be increasing or decreasing? Not available for partial sorting.

...

arguments to be passed to or from methods or (for the default methods and objects without a class) to sort.int.

na.last

for controlling the treatment of NAs. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed.

See Also

order2 base::sort base::order


Text Color

Description

Determine text color based on background color

Usage

text_color(
  background,
  threshold = 186,
  w3c = FALSE,
  dark = "black",
  light = "white"
)

Arguments

background

A vector of background colors; supports R color names and hexadecimal codes

threshold

Intensity threshold for light/dark cutoff; intensities greater than theshold yield dark, others yield light

w3c

Use W3C formula for calculating background text color; ignores threshold

dark

Color for dark text

light

Color for light text

Value

A named vector of either dark or light, depending on background; names of vector are background

Source

https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color

See Also

Other color_theory: blend_colors(), col2hex(), contrast-theory

Examples

text_color(background = c('black', 'white', '#E76BF3'))