When i use the basic pipe operator |> instead of the magrittr pipe (%>%) I see a warning triangle displayed in RStudio IDE saying argument 'data' is missing with no default.
What is going wrong?
library(tidyverse)
library(gt)
mtcars |> count(cyl)
mtcars %>% count(cyl)
mtcars |> gt() # warning on this line
mtcars %>% gt()
By default, the pipe passes the object on its left hand side to the first argument of the function on the right-hand side. %>% allows you change the placement with a . placeholder. For example, x %>% f(1) is equivalent to f(x, 1) but x %>% f(1, .) is equivalent to f(1, x) . R 4.2.0 added a _ placeholder to the base pipe, with one additional restriction: the argument has to be named. For example, x |> f(1, y = _) is equivalent to f(1, y = x)
So both R versions should work as shown in the reprex below.
I am using RStudio 2022.02.3+492 and gt 0.6.0.
Warning is both on R 4.2.0 and R 4.1.1
The code runs fine, but i don't understand why it gives a warning.
I can get rid of the warning by using data = _ , but there should be no need to do so.
When piping several gt command its looks pretty dangerous.
RStudio
2022.02.3+492 "Prairie Trillium" Release (1db809b8323ba0a87c148d16eb84efe39a8e7785, 2022-05-20) for Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 17763)