when you pipe forward, you make a new object, but to return that changed object you need to have assigned it to a name
either
market <- function(x){
x<- x%>%
filter(str_detect(2, "NA", negate = TRUE))%>%
select(1:25, -2)%>%
gather(key = "Year", value = "Volume", -1)
return(x)
}
or
market <- function(x){
x%>%
filter(str_detect(2, "NA", negate = TRUE))%>%
select(1:25, -2)%>%
gather(key = "Year", value = "Volume", -1) -> x
return(x)
}
they assign your results back to the same x name, these two codes are equivalent
library(magrittr) also allows a two way pipe, that achieves the same
market <- function(x){
x%<>%
filter(str_detect(2, "NA", negate = TRUE))%>%
select(1:25, -2)%>%
gather(key = "Year", value = "Volume", -1)
return(x)
}