I don't understand how the new native pipe placeholder works. Prior to R 4.2, the native pipe didn't have a placeholder so you needed to create a dedicated anonymous function in order to pass the piped object to function arguments other than the first. Now, after the release of R 4.2, the native pipe got a dedicated placeholder _
too. I'm also aware that this new placeholder only works if the name of the argument that will receive the placeholder is directly stated: R 4.2.0 Native Placeholder. However I'm still facing some trouble and can't fully understand how to implement it.
I'll give you an example. I wrote a simple piped code chunk that takes an object and returns how many missing values there are in each column.
x = c(NA, NA, 1, NA, 1, 2)
m = matrix(x, nrow = 3, ncol = 2)
m
# [,1] [,2]
# [1,] NA NA
# [2,] NA 1
# [3,] 1 2
#### CHECK FOR MISSING VALUES ####
m |>
{ \(.) .colSums(is.na(.), NROW(.), NCOL(.)) }() |>
{ \(sum.NA) rbind(names(m), sum.NA) }() |>
t()
# sum.NA
# [1,] 2
# [2,] 1
The previous code uses the anonymous function method and works nicely. I'm not able to change this code into properly using the new placeholder. Do you have any suggestion?