I am trying to pipe into expss::uselabels()
.
A simple replicable example of what I'm trying to do (without the pipe), would be a labelled lm()
model:
library(tidyverse) library(expss) df <- mtcars df <- apply_labels(df, cyl = "Number of Cylinders", disp = "Displacement") fit_1 <- df %>% use_labels(lm(formula = mpg ~ disp + cyl)) summary(fit_1)
which gives labelled coefficients in the lm
output:
# > Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 34.66099 2.54700 13.609 4.02e-14 *** #> Displacement -0.02058 0.01026 -2.007 0.0542 . #> `Number of Cylinders` -1.58728 0.71184 -2.230 0.0337 *
My questions: can I first take an lm()
model and then pipe into use_labels()
? I've tried below, but I must be refering to the two paramaters incorrectly.
fit_1<- df %>% lm(formula = mpg ~ disp + cyl) %>% use_labels(data = .x, expr = .y)
substitute()
to delay evaluation ofexpr
, which I don't think will work with a pipe because the left hand side is always evaluated before the right hand side. Your last pipeline wouldn't work regardless, becausedf
is gone by the time you get touse_labels()
, and.x
and.y
aren't anything; the only special variable with pipes is.
which is the evaluated LHS being passed in and used for specifying what parameter it should be passed to. – alistaire%T>%
pipe , but then you would have to call your model twice:fit_3 <- df %T>% lm(mpg ~ disp + cyl, .) %>% use_labels(., lm(mpg ~ disp + cyl, .))
– TimTeaFan