trim <- function (x){ gsub("^\\s+|\\s+$", "", x) } trim(" test ") ##test