Handy vector construction from string
Arguments
- x
String. A string to construct a vector from (see examples). If
x
has length > 1,stom::as_c_num
orstom::as_c_chr
would be called (depending on input type) to print out the concatenation syntaxc(...)
in the console.- cast_num
Boolean. Whether to convert string to numeric when applicable. See examples.
Examples
# Construct vector from string
as_vec("a b c")
#> [1] "a" "b" "c"
as_vec("d, e f") # Commas have precedence over spaces
#> [1] "d" "e f"
# Auto typecasting
as_vec("1 2 -3.1")
#> [1] 1.0 2.0 -3.1
as_vec("04, 05")
#> [1] 4 5
as_vec("04, 05", cast_num=FALSE) # Disable typecasting
#> [1] "04" "05"