b <- c("books", " ", "animals", "frogs")
#My code:
b[!grepl("^\\s+$", b)]
[1] "books" "animals" "frogs"
#Now, I am working to figure out this solution with stringr package.
str_remove_all(b, "^\\s+$")
[1] "books" "" "animals" "frogs"
The output shows "" where my new code fails. Any solution to get the result like my first code?
b[nzchar(trimws(b))]