3

I use tidyverse (and its environment) almost every day and from time to time I have to come back to previous/old analyses. Unfortunately, it's not easy to keep up the track of the changes that have been made to the package.

This script is pretty functional and it performs what I want (it is used inside a function with other commands)

ds <- data.frame(result = rnorm(100,5,2),
                 time = c("1","2"))
library(tidyverse)
library(broom)

ds %>% 
  summarise_at(vars("result"),
               funs(list(tidy(t.test(. ~ time, paired=TRUE))))) %>% map(1)

I know this is not the most elegant syntax. Now, this message comes after the command:

funs() is soft deprecated as of dplyr 0.8.0 Please use a list of either functions or lambdas:

  # Simple named list: 
  list(mean = mean, median = median)

  # Auto named with `tibble::lst()`: 
  tibble::lst(mean, median)

  # Using lambdas
  list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))

All my attempt to fix it gives me a message...

> ds %>% 
+   summarise_at(vars("result"),
+                lst(tidy(t.test(. ~ time, paired=TRUE)))) %>% map(1)
Error in model.frame.default(formula = . ~ time) : 
  invalid type (list) for variable '.'
> ds %>% 
+   summarise_at(vars("result"),
+                list(list(tidy(t.test(. ~ time, paired=TRUE))))) %>% map(1)
Error in model.frame.default(formula = . ~ time) : 
  invalid type (list) for variable '.'
> ds %>% 
+   summarise_at(vars("result"),
+                list(list(tidy(~ t.test(. ~ time, paired=TRUE))))) %>% map(1)
Error: No tidy method for objects of class formula

So.. first question: Any clue about fixing it?
second: where can I follow these (constant) updates?
Three: I use tidyverse because I enjoy the way it deals with commands. It is pretty intuitive, but I see as an important side effect this constantly changes ... Should I try to move all my routines to R base (Probably, R base will not change its function ...)?

Thanks all.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Luis
  • 1,388
  • 10
  • 30

1 Answers1

1

How about this?

ds <- data.frame(result = rnorm(100,5,2),
                 time = c("1","2"))

library(tidyverse)
library(broom)

ds %>% 
  summarise_at(vars("result"),
               list(~ list(tidy(t.test(. ~ time, paired=TRUE))))) %>% map(1)
#> $result
#> # A tibble: 1 x 8
#>   estimate statistic p.value parameter conf.low conf.high method
#>      <dbl>     <dbl>   <dbl>     <dbl>    <dbl>     <dbl> <chr> 
#> 1   -0.719     -1.77  0.0823        49    -1.53    0.0955 Paire~
#> # ... with 1 more variable: alternative <chr>

Created on 2019-09-04 by the reprex package (v0.3.0)

Tung
  • 26,371
  • 7
  • 91
  • 115