rstringvariable-types

R - Determine if a variable is a string


Is there a way to determine if an R variable is a single string? is.character looked promising, but there was one issue: is.character(c("a", "b")) also returned TRUE which is not what I want.


Solution

  • Based on the comments, this is my current solution:

    isSingleString <- function(input) {
        is.character(input) & length(input) == 1
    }