ez.clcolnames: sanitize col names

View source: R/frame.R

ez.clcolnamesR Documentation

sanitize col names

Description

replace certain characters (all occurrence) in all column names, using regular expression and gsub(). see also ez.clcoldata

Usage

ez.clcolnames(
  df,
  pattern = "[[:space:][:punct:]]",
  replacement = ".",
  fixed = FALSE,
  ignore.case = FALSE,
  perl = TRUE,
  col = NULL
)

Arguments

df

df

pattern

search

replacement

replacement

fixed

FALSE=regex mode on, TRUE=regex mode off

ignore.case

if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

perl

Perl-compatible regexps be used, without perl, [[:space:][:punct:]] works, but not [\s[:punct:]] so seems always a good idea to turn on perl compatible. see gsub. ignored when fixed=TRUE

col

NULL=all columns, otherwise restricted to specified cols, eg, ( internally evaluated by eval('dplyr::select()') )
'c(sample_num,mother_num)' (quoted) or c("sample_num","mother_num") (not quoted)
1:4 (not quoted)
'col1:col3' (quoted)
'-(ABCB1_c1236t:pgp_rs2032582)', '-c(neonate_admit_NICU,BDNF)' (quoted)

Value

returns a new df with column names cleaned, old df does not change

See Also

see also ez.clcoldata

Examples

all upper to lower using regex (ignore.case=FALSE or TRUE does not matter)
ez.clcolnames(iris,pattern='([[:upper:]])', replacement = '\\L\\1', perl = TRUE, ignore.case=FALSE)

jerryzhujian9/ezmisc documentation built on March 9, 2024, 12:44 a.m.