Re-exporting the magrittr pipe operator

April 27, 2018
By

(This article was first published on petermeissner, and kindly contributed to R-bloggers)

… or how I stoped worrying and wrote a blog post to remember it ad infinitum.

Magrittr’s pipe operator is one of those newish R-universe features that I
really want to have around whenever I put some lines into an R-console.
This is even TRUE when writing a package.

So the first thing I do is put magrittr into the DESCRIPTION file and add
an __imports.R file to the packages R/-directory with the following lines:

#' re-export magrittr pipe operator
#'
#' @importFrom magrittr %>%
#' @name %>%
#' @rdname pipe
#' @export
NULL

These lines import and re-export the pipe operator (%>%) therewith allowing to
use it within my package but also beeing able to use it interactively whenever
the package is loaded.

Best of all these lines will also ensure passing all
package checks (CRAN complient) and preventing any
“The following objects are masked from …” messages.

Last but not least the file name “__imports.R” serves two purposes
(1) making the it appear at the very beginning of an alphabetical sorted lists of
file names and (2) second giving it a speaking name to inform – however
reads the file name – that some R “Imports” are most likely happening inside.

Happy coding!

PS.: Those lines above require the usage of roxygen2 as documentation framework.

To leave a comment for the author, please follow the link and comment on their blog: petermeissner.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)