camr_list_elements: List Elements as Embedded in R Code

View source: R/R04-Data_wrangling.R

camr_list_elementsR Documentation

List Elements as Embedded in R Code

Description

Function to generate R code listing the distinct elements of x (e.g., embedding them in a concatenate or list statement).

Usage

camr_list_elements(
  x,
  left = "  \"",
  right = "\",\n",
  first = "c(\n",
  last = ")",
  drop_last = ",",
  console = TRUE
)

Arguments

x

A vector of values.

left

A character string to attach to the left of each element in x.

right

A character string to attach to the right of each element in x.

first

A character string to attach to the left of the final collapsed string.

last

A character string to attach to the right of the final collapsed string.

drop_last

An optional character string indicating any patterns to remove from the final element.

console

A logical value; if TRUE displays the results in the console window, otherwise returns a character string.

Value

Either a message to the console window or a character string.

Examples

camr_list_elements( LETTERS[1:3] )

# Operates only on distinct values
camr_list_elements( rep( LETTERS[1:3], each = 2 ) )

# Can adjust how elements are embedded in R code
camr_list_elements( 1:3, left = '  ', right = ',\n' )
camr_list_elements( LETTERS[1:3], first = 'list(\n' )


rettopnivek/camrprojects documentation built on March 26, 2024, 9:17 a.m.