代码之家  ›  专栏  ›  技术社区  ›  stackinator Brenton Wiernik

如何以NULL结束dplyr管道?允许轻松评论/取消评论

  •  8
  • stackinator Brenton Wiernik  · 技术社区  · 7 年前
    library(tidyverse)
    ggplot(mpg, aes(hwy)) + 
      geom_histogram() + 
      theme_classic() + 
      NULL
    

    你还记得你的ggplot命令结尾的酷把戏吗 NULL theme_classic() + 我的代码仍然可以正常工作,因为 就在最后。

    ggplot(mpg, aes(hwy)) + 
      geom_histogram() + 
      # theme_classic() + 
      NULL
    

    好 啊。那么,如何对dplyr管道执行相同的操作呢?我想把 无效的 最后,我可以评论/取消注释 count(cyl) 随意的。但这不太管用。我收到一封信 Error in .() : could not find function "." .

    mtcars %>% 
      as_tibble() %>% 
      count(cyl) %>% 
      NULL
    
    mtcars %>% 
      as_tibble() %>% 
      # count(cyl) %>% 
      NULL
    
    1 回复  |  直到 7 年前
        1
  •  12
  •   aosmith    7 年前

    我见过 I()

    mtcars %>% 
         as_tibble() %>% 
         # count(cyl) %>% 
         I()
    

    注意,使用 我() 预习班 "AsIs" 在物体上。如果在以后的某个步骤中使用指定的对象,可能会导致意外的后果。

    其他可能的评论,似乎都没有
    identity() force()
    print() {.} return()

    推荐文章