RStudio IDE warning when using native pipe and gt

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()

image

The {base} pipe, |> was updated from R4.1 to R4.2 (See this chapter in r4ds).

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.

library(gt)
mtcars |> dplyr::count(cyl)   
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14

What versions of R and RStudio?

The first argument for gt( ) is data, so the native pipe should work without any warning.

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.

image

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)

Matrix products: default

locale:
[1] LC_COLLATE=English_Netherlands.1252 LC_CTYPE=English_Netherlands.1252
[3] LC_MONETARY=English_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=English_Netherlands.1252

attached base packages:
[1] stats graphics grDevices datasets utils methods base

other attached packages:
[1] gt_0.6.0 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.9 purrr_0.3.4 readr_2.1.2
[7] tidyr_1.2.0 tibble_3.1.7 ggplot2_3.3.6 tidyverse_1.3.1

loaded via a namespace (and not attached):
[1] cellranger_1.1.0 pillar_1.7.0 compiler_4.2.0 dbplyr_2.2.0 tools_4.2.0 digest_0.6.29
[7] checkmate_2.1.0 jsonlite_1.8.0 lubridate_1.8.0 lifecycle_1.0.1 gtable_0.3.0 pkgconfig_2.0.3
[13] rlang_1.0.2 reprex_2.0.1 rstudioapi_0.13 DBI_1.1.2 cli_3.3.0 haven_2.5.0
[19] fastmap_1.1.0 xml2_1.3.3 withr_2.5.0 httr_1.4.3 sass_0.4.1 fs_1.5.2
[25] generics_0.1.2 vctrs_0.4.1 hms_1.1.1 grid_4.2.0 tidyselect_1.1.2 glue_1.6.2
[31] R6_2.5.1 fansi_1.0.3 readxl_1.4.0 tzdb_0.3.0 modelr_0.1.8 magrittr_2.0.3
[37] htmltools_0.5.2 backports_1.4.1 scales_1.2.0 ellipsis_0.3.2 rvest_1.0.2 assertthat_0.2.1
[43] colorspace_2.0-3 renv_0.15.1 utf8_1.2.2 stringi_1.7.6 munsell_0.5.0 broom_0.8.0
[49] crayon_1.5.1

1 Like

Are the three warnings all the same? If {gt} is the only package generating these warnings, you could try the latest version on github.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.