That last element in the pipeline is neccessary because otherwise my item is in a one element-long list and I want the object out from the list. unlist doesn't work because it flattens out the data structure (often a tibble) within the nested column.
Now the problem is that if I convert this to a native pipe pipeline, |> .[[1]] produces the following error: Error: function '[[' not supported in RHS call of a pipe
My shortcut is to create a function like first <- function(x) x.[[1]], but surely there is already a native way to do this.
I think you are asking for a general base r way to select the first item from a list, base::head(x,n=) can be used for this, and there is base::tail also
Thanks, pluck did it for me. I kept remembering hoist which is the wrong function, but not pluck.
For the record, base::head doesn't seem to work for this, unless I'm implementing it wrong. It does select the item from the list, but it is still returned as a one (or more) element list.
> tibble(A=list(tibble(a=1:2, b=3:4))) |> pull(A) |> head(1)
# still a list:
[[1]]
# A tibble: 2 × 2
a b
<int> <int>
1 1 3
2 2 4