'Add base R script to function?

I have this function:

my_fun <- function(x) { 
  x %>%       
    separate_rows(tags, sep=',\\s*') %>%
    separate(tags, c('tags', 'Value'), sep='\\s*-\\s*', fill='right') %>%
    mutate(tags=trimws(tags)) %>% 
    count(Year, tags) %>%
    pivot_wider(names_from=tags, values_from=n, values_fill=0) %>%
    adorn_totals("row") 
}

Is it possible to add these two lines to the function, after "adorn_totals"? The first one orders the columns by the last row value (minus the first one), and the second sums all rows (minus the first one) and adds it as a new column

[c(1, order(-[nrow(), -1]) + 1)]
rowSums([, -1])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source