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.
R - Determine if a variable is a string
Asked Answered
Based on the comments, this is my current solution:
isSingleString <- function(input) {
is.character(input) & length(input) == 1
}
© 2022 - 2024 — McMap. All rights reserved.
is.character(c("a", "b")) & length(c("a", "b")) == 1
– Punkclass(c("a","b")) & length(c("a","b"))==1
. Note there's no such thing as a variable in R really.c("a","b")
is really 2 different objects in a function that prepares them for assignment to a vector or list, both of which are character, i.e. string. – Kyneclass
andis.character
are built-in. when would they not work? – Kyne