I have this string vector (for example):
str <- c(\"this is a string current trey\", \"feather rtttt\", \"tusla\", \"laq\")
Use the stringi package and stri_count:
stringi
stri_count
require(stringi) str <- c( "this is a string current trey", "nospaces", "multiple spaces", " leadingspaces", "trailingspaces ", " leading and trailing ", "just one space each") > stri_count(str,regex="\\S+") [1] 6 1 2 1 1 3 4