delim: Error-checked string delimiting

View source: R/delim.R

delimR Documentation

Error-checked string delimiting

Description

Simplified and extended base::paste and base::paste0. There are both primary functions using user-specified delimiters and convenience functions for common delimiters.

Usage

delim()

da(d, ...)

dw(d, ...)

daw(d, D, ...)

dww(d, D, ...)

da_0(...)

da_1(...)

da0(...)

da1(...)

da_b(...)

da_c(...)

da_d(...)

da_g(...)

da_p(...)

da_q(...)

da_s(...)

da_t(...)

dw_0(...)

dw0(...)

dw_1(...)

dw1(...)

dw_b(...)

dw_c(...)

dw_d(...)

dw_g(...)

dw_p(...)

dw_q(...)

dw_s(...)

dw_t(...)

daw_00(...)

daw_01(...)

daw00(...)

daw01(...)

daw_0b(...)

daw_0c(...)

daw_0d(...)

daw_0g(...)

daw_0p(...)

daw_0q(...)

daw_0s(...)

daw_0t(...)

daw_10(...)

daw_11(...)

daw10(...)

daw11(...)

daw_1b(...)

daw_1c(...)

daw_1d(...)

daw_1g(...)

daw_1p(...)

daw_1q(...)

daw_1s(...)

daw_1t(...)

daw_b0(...)

daw_b1(...)

daw_bb(...)

daw_bc(...)

daw_bd(...)

daw_bg(...)

daw_bp(...)

daw_bq(...)

daw_bs(...)

daw_bt(...)

daw_c0(...)

daw_c1(...)

daw_cb(...)

daw_cc(...)

daw_cd(...)

daw_cg(...)

daw_cp(...)

daw_cq(...)

daw_cs(...)

daw_ct(...)

daw_d0(...)

daw_d1(...)

daw_db(...)

daw_dc(...)

daw_dd(...)

daw_dg(...)

daw_dp(...)

daw_dq(...)

daw_ds(...)

daw_dt(...)

daw_g0(...)

daw_g1(...)

daw_gb(...)

daw_gc(...)

daw_gd(...)

daw_gg(...)

daw_gp(...)

daw_gq(...)

daw_gs(...)

daw_gt(...)

daw_p0(...)

daw_p1(...)

daw_pb(...)

daw_pc(...)

daw_pd(...)

daw_pg(...)

daw_pp(...)

daw_pq(...)

daw_ps(...)

daw_pt(...)

daw_q0(...)

daw_q1(...)

daw_qb(...)

daw_qc(...)

daw_qd(...)

daw_qg(...)

daw_qp(...)

daw_qq(...)

daw_qs(...)

daw_qt(...)

daw_s0(...)

daw_s1(...)

daw_sb(...)

daw_sc(...)

daw_sd(...)

daw_sg(...)

daw_sp(...)

daw_sq(...)

daw_ss(...)

daw_st(...)

daw_t0(...)

daw_t1(...)

daw_tb(...)

daw_tc(...)

daw_td(...)

daw_tg(...)

daw_tp(...)

daw_tq(...)

daw_ts(...)

daw_tt(...)

dww_00(...)

dww_01(...)

dww_0b(...)

dww_0c(...)

dww_0d(...)

dww_0g(...)

dww_0p(...)

dww_0q(...)

dww_0s(...)

dww_0t(...)

dww_10(...)

dww_11(...)

dww_1b(...)

dww_1c(...)

dww_1d(...)

dww_1g(...)

dww_1p(...)

dww_1q(...)

dww_1s(...)

dww_1t(...)

dww_b0(...)

dww_b1(...)

dww_bb(...)

dww_bc(...)

dww_bd(...)

dww_bg(...)

dww_bp(...)

dww_bq(...)

dww_bs(...)

dww_bt(...)

dww_c0(...)

dww_c1(...)

dww_cb(...)

dww_cc(...)

dww_cd(...)

dww_cg(...)

dww_cp(...)

dww_cq(...)

dww_cs(...)

dww_ct(...)

dww_d0(...)

dww_d1(...)

dww_db(...)

dww_dc(...)

dww_dd(...)

dww_dg(...)

dww_dp(...)

dww_dq(...)

dww_ds(...)

dww_dt(...)

dww_g0(...)

dww_g1(...)

dww_gb(...)

dww_gc(...)

dww_gd(...)

dww_gg(...)

dww_gp(...)

dww_gq(...)

dww_gs(...)

dww_gt(...)

dww_p0(...)

dww_p1(...)

dww_pb(...)

dww_pc(...)

dww_pd(...)

dww_pg(...)

dww_pp(...)

dww_pq(...)

dww_ps(...)

dww_pt(...)

dww_q0(...)

dww_q1(...)

dww_qb(...)

dww_qc(...)

dww_qd(...)

dww_qg(...)

dww_qp(...)

dww_qq(...)

dww_qs(...)

dww_qt(...)

dww_s0(...)

dww_s1(...)

dww_sb(...)

dww_sc(...)

dww_sd(...)

dww_sg(...)

dww_sp(...)

dww_sq(...)

dww_ss(...)

dww_st(...)

dww_t0(...)

dww_t1(...)

dww_tb(...)

dww_tc(...)

dww_td(...)

dww_tg(...)

dww_tp(...)

dww_tq(...)

dww_ts(...)

dww_tt(...)

Arguments

d, D

Character scalar delimiters.

...

An arbitrary number of atomic vector arguments to be delimited. Argument in ... must be recyclable for functions that delimit across ... arguments as the first or only step (i.e., functions with names beginning with da).

Details

Primary functions

  dww   Delimit elements within each (atomic vector) ... argument using delimiter d, then delimit elements within the resulting vector using delimiter D. Produces a character scalar of ...length() substrings delimited by D where each substring contains sub-substrings delimited by d.
   
  daw Delimit across corresponding elements of (recyclable atomic vector) ... arguments using delimiter d, then delimit elements within the resulting character vector using delimiter D. Produces a character scalar of ...length() substrings delimited by D where each substring contains max(lengths(list(...))) sub-substrings delimited by d.
   
  dw Delimits elements within each (atomic vector) ... argument using delimiter d. Produces a character vector of ...length() substrings delimited by d.
   
  da Delimits across corresponding elements of (recyclable atomic vector) ... arguments using delimiter d. Produces a character vector of max(lengths(list(...))) substrings delimited by d.


Common-delimiter convenience functions

Convenience function names are constructed by append 1 or 2 codes for common delimiters to the function name as follows (where {x} and {y} are placeholders for common-delimiter codes):

  ⁠daw_{x}{y}⁠   Delimits across using {x} then within using {y}.
   
  ⁠dww_{x}{y}⁠ Delimits within using {x} then again using {y}.
   
  ⁠da_{x}⁠ Delimits across using {x}.
  ⁠dw_{x}⁠ Delimits within using {x}.


Common delimiters are encoded as:

  Code   Name   Delimiter
  '0' blank   ''
  '1' space   ' '
  'b' broken pipe   '¦'
  'c' colon   ':'
  'd' dot   '.'
  'g' grammatical comma^{(1)}   ', '
  'p' pipe   '|'
  'q' back-tick quote   '``'
  's' simple comma^{(1)}   ','
  't' tilde   '~'
  ^{(1)} 'Grammatical comma' vs. 'simple comma' indicates whether the function produces grammatical comma-delimited lists vs. simple comma-delimited values (e.g., '1, 2, 3' vs. '1,2,3').

Value

A character scalar

⁠daw_{x}{y}, dww_{x}{y}, daw, dww⁠

A character vector

⁠da_{x}, dw_{x}, da, dw⁠

See Also

Other strings: blank(), chn(), fsub(), gr, ipat(), makestr(), markdown_help(), maxnch(), ox(), ox_vals(), pgrid_help(), revstr(), spaces(), ss_help(), tocase(), weave()

Examples

# delimit across using delimiter '|'.
# aliases paste(1:3, 4:6, sep = '|').
da('|', 1:3, 4:6)

# delimit within using delimiter ':'.
# aliases sapply(list(1:3, 4:6), paste0, collapse = ':').
dw(':', 1:3, 4:6)

# delimit across using '|', then within using ':'
# aliases paste(..., sep = d, collapse = D)
daw('|', ':', 1:3, 4:6)

# delimit within using '|' then again within using ':'.
# aliases paste0(sapply(list(...), paste0, collapse = d), collapse = D).
dww('|', ':', 1:3, 4:6)

# delimit across using pipe (encoded by 'P' suffix in function name).
da_p(1:3, 4:6)

# delimit within using colon (encoded by 'C' suffix in function name).
dw_c(1:3, 4:6)

# delimit across using pipe, then within using colon.
daw_pc(1:3, 4:6)

# delimit within using colon, then again using pipe.
dww_cp(1:3, 4:6)

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.