trimws

trimws(x, which='both', whitespace='[ \\t\\r\\n]')

Strip whitespace from strings. which: ‘both’, ‘left’, ‘right’. Vectorised.