I think you are looking for the dreaded eval(parse(...))
construct.
Try:
d <- "3:10"
eval(parse(text = d))
# [1] 3 4 5 6 7 8 9 10
An interesting approach to this could be:
Reduce(":", as.numeric(strsplit(d, ":", TRUE)[[1]]))
# [1] 3 4 5 6 7 8 9 10
And, whaddyaknow! I wouldnathunkit, but it's faster than eval(parse(...))
(but your approach in the comment is faster yet).
fun1 <- function() Reduce(":", as.numeric(strsplit(d, ":", TRUE)[[1]]))
fun2 <- function() eval(parse(text = d))
fun3 <- function() {
s <- as.numeric(strsplit(d, ":", fixed = TRUE)[[1]])
s[1]:s[2]
}
library(microbenchmark)
microbenchmark(fun1(), fun2(), fun3())
# Unit: microseconds
# expr min lq median uq max neval
# fun1() 24.375 26.0865 32.2865 55.8070 113.751 100
# fun2() 108.192 112.4680 121.4490 204.8375 453.720 100
# fun3() 8.553 10.6920 12.8300 20.9550 40.198 100