I have a vector: c(1,2,3)
Calling print() on this value gives "[1] 1 2 3"
Is there a function that takes a vector and gives the string "c(1,2,3)"?
I have a vector: c(1,2,3)
Calling print() on this value gives "[1] 1 2 3"
Is there a function that takes a vector and gives the string "c(1,2,3)"?
I've never heard of such a function. Perhaps you should quickly write one yourself?
toString <- function(a){
output <- "c(";
for(i in 1:(length(a)-1)){
output <- paste(output, a[i], ",", sep="")
}
output <- paste(output, a[length(a)], ")\n", sep="")
cat(output)
}
You can use deparse
:
R> x <- c(1, 2, 3)
R> deparse(x)
[1] "c(1, 2, 3)"
R> class(deparse(x))
[1] "character"