1#' Check if a string is whitespace. 2#' 3#' Return \code{TRUE} if there are only whitespace characters in the string and there is at least 4#' one character, \code{FALSE} otherwise. 5#' 6#' @param str A character vector. 7#' 8#' @return A logical vector. 9#' 10#' @references \url{https://docs.python.org/3/library/stdtypes.html#str.isspace} 11#' 12#' @examples 13#' pystr_isspace(" ") 14#' pystr_isspace(" a ") 15#' 16#' @export 17pystr_isspace <- function(str) { 18 return(vapply(str, function(x) pystr_isspace_(x), logical(1), USE.NAMES = FALSE)) 19} 20 21pystr_isspace_ <- function(str) { 22 if(nchar(str) == 0) {return(FALSE)} 23 24 for(i in 1:nchar(str)) { 25 letter = substr(str, i, i) 26 if(!(letter == " ")) { 27 return(FALSE) 28 } 29 } 30 31 return(TRUE) 32} 33