Open jonocarroll opened 6 days ago
I see the advantage for sure. One complication of taking the 'splatted' arguments instead of a single argument is that they need to be combined into a vector; for a list that isn't a problem
rlang::list2(1, "2", 3i, )
[[1]]
[1] 1
[[2]]
[1] "2"
[[3]]
[1] 0+3i
but for a vector I'd need to call c(...)
inside as_vec()
which would "hide" the coercion
c(1, "2", 3i)
[1] "1" "2" "0+3i"
On the other hand, someone calling as_vec(c(a, b, c))
isn't going to "see" the coercion either.
{rlang} does provide vector constructors that use dynamic-dots, but it seems to error on coercion
rlang::chr(1, "2", 3i, )
Error:
! Can't convert a double vector to a character vector.
rlang::chr("1", "2", "3i", )
[1] "1" "2" "3i"
which may be why there's not a generalised version.
I'll keep thinking on this - perhaps there's a way.
Could an optional FUN.VALUE (like vapply) or cast_to argument make sense in this case?
Then maybe use: https://vctrs.r-lib.org/reference/vec_cast.html
One suggestion, it could be great to be able to set:
as_vec( a, b, )
Just like rlang::list2 does using ... param.
Originally posted by @jrosell in https://github.com/jonocarroll/vec/issues/1#issuecomment-2402607650