new package: tidylog - feedback for basic dplyr operations

dplyr
package

#22

You can make sure that tidylog is always positioned at the right place on the search path by doing :

.onLoad <- function(libname, pkgname){
  setHook(packageEvent("dplyr", "attach"),
          function(...) {
            detach("package:tidylog")
            library(tidylog, warn.conflicts = FALSE, quietly = TRUE )}
} 

`


#23

Well conceived. Lots of sound programming concepts. Conceptually helpful to have meaningful failure as well. See how the tableone package provides feedback if a function attribute calls a variable that is not present in the data table.


#24

This is a good idea, but R CMD CHECK complains that a package shouldn't change the search path. So with this code the package probably wouldn't make it to CRAN.


#25

This is good to know, thanks!


#26

If you want to avoid masking all the dplyr functions and log selectively you could use my package mmpipe and define an adequate operator, here is a quick implementation :

# devtools::install_github("moodymudskipper/mmpipe")
library(dplyr)
library(mmpipe)
# we define a pipe that will replace the function used on the rhs by its 
# equivalent in the tidylog package
mmpipe::add_pipe(`%tlog>%`, {
  # equivalent to x <- list(my_fun = quote(tidlog::my_fun))
  x <- setNames(list(call("::",quote(tidylog),body[[1]])),as.character(body[[1]]))
  # use x to substitute the original fun with the tidylog one
  eval(substitute(substitute(body,x),list(body=body)))}
)

Let's use it and log only the filter operation :

iris %>% 
  select(Petal.Length,Species) %tlog>%
  filter(Petal.Length > 5) %>%
  head
# filter: removed 108 out of 150 rows (72%)
#   Petal.Length    Species
# 1          5.1 versicolor
# 2          6.0  virginica
# 3          5.1  virginica
# 4          5.9  virginica
# 5          5.6  virginica
# 6          5.8  virginica

#27

This looks like a great package Ben! Very useful info to have automatically returned.

Thanks for the contribution. We'll be giving it a trial run in our current project and will send comments/suggestions/bug reports as appropriate.