On Sun, Dec 4, 2022 at 1:22 PM <avi.e.gr...@gmail.com> wrote:
>
> This may be a fairly dumb and often asked question about some functions like 
> strsplit()  that return a list of things, often a list of ONE thing that be 
> another list or a vector and needs to be made into something simpler..
>
> The examples shown below have used various methods to convert the result to a 
> vector but why is this not a built-in option for such a function to simplify 
> the result either when possible or always?
>
> Sure you can subset it with " [[1]]" or use unlist() or as.vector() to coerce 
> it back to a vector. But when you have a very common idiom and a fact that 
> many people waste lots of time figuring out they had a LIST containing a 
> single vector and debug, maybe it would have made sense to have either a 
> sister function like strsplit_v() that returns what is actually wanted or 
> allow strsplit(whatever, output="vector") or something giving the same result.
>
> Yes, I understand that when there is a workaround, it just complicates the 
> base, but there could be a package that consistently does things like this to 
> make the use of such functions easier.

The next version of stringr (currently being processed by CRAN)
provides str_split_1() for exactly this purpose.

Hadley

-- 
http://hadley.nz

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to