Use explicit namespace with infix operator

后端 未结 1 1748
自闭症患者
自闭症患者 2021-01-16 16:33

The dplyr R package has the %>% operator, which is a custom infix operator. If one attaches the namespace with library(dplyr) one c

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-16 16:57

    Just import the pipe operator, by adding a line like

    importFrom(magrittr, "%>%")
    

    in your NAMESPACE file, or if you're using roxygen2, putting

    #' @importFrom magrittr %>%
    

    into one of your .R files to do the same thing.

    You may or may not want to export it as well. Do export it with a line like

    export("%>%")
    

    in your NAMESPACE file or with roxygen2

    #' @export
    magrittr::`%>%`
    

    if you want your users to use the pipe operator when they are using your package. Don't export it if you only need it to be available internally.

    0 讨论(0)
提交回复
热议问题