how to import with roxygen packages the pipe opera

2019-07-08 08:53发布

问题:

I want to build a package with some functions i wrote. Now my problem is, that i cannot use the pipe-operator %>% with dplyr. I create the package with roxygen2.

If i write the dplyr-commands without %>%, everything works fine.

inside the code:

#'
#' @import dplyr readr mailR writexl
#' @importFrom dplyr %>%
#' @name %>%
#' 
#' @export
#'

I wrote:

DESCRIPTION

LazyData: true
RoxygenNote: 6.0.1
Imports: dplyr 

roxygen2 generates:

NAMESPACE

...
importFrom(dplyr,"%>%")
...

回答1:

Usually you would import the pipe operator from magrittr.

You could add a file to the R dir of your package that looks somewhat like this:

#' Pipe
#'
#' Put description here
#'
#' @importFrom magrittr %>%
#' @name %>%
#' @rdname pipe
#' @export
#' @param lhs,rhs specify what lhs and rhs are
#' @examples
#' # some examples if you want to highlight the usage in the package
NULL

In addition you have to add magrittr to your imports in the description file of your package.