Search code examples
rglmsummarymagrittr

MagrittR T-pipe for the summary.glm function. Simple issue


I'm actually running on a problem with the T pipe. I'm trying to do 3 things in the same chain:

  1. Fit my GLM
  2. Save it in a variable
  3. Print it's summary

So I'm trying the following syntax:

my_variable <- data %>%
    glm(Responce ~ Variables, family) %T>%
    summary

Which does not work as expected. The glm get's fitted, but the summary wont show itself. So I'm force to break it into 2 chains:

my_variable <- data %>%
    glm(Responce ~ Variables, family)

my_variable %>% summary

So I'm thinking: Either I didn't get the functionality of the T-pipe, either it's not properly coded and mess around with the summary function.

Because if I try:

my_variable <- data %>%
    glm(Responce ~ Variables, family) %T>%
    plot

it works well.

Some ideas?


Solution

  • When you just type summary(something) in the console, print is called implicitly. It's not the case in your pipe call, so you need to explicitly call print.

    Because the unbranching of %T>% works for one operation only you'll have to compose print and summary :

    my_variable <- data %>%
        glm(Responce ~ Variables, family) %T>%
        {print(summary(.)}
    

    You need curly braces and the dot else the glm output would be passed as the first argument to print.