Computing features over the same dataframe
If I was reviewing this code professionally, my first comment would be that you should stick to a style guide. This will govern things like spacing between statements, brackets, operators etc. It can be seen as a kind of nitpicky remark (I certainly did at first) but having a consistent style massively aids readability for you and for others.

The second (style) comment would be that your code is halfway between very pipe-based code and "standard" R style (lots of assignment). This makes it difficult to read. If you're going to go with pipes, stick with it.

Also, when using an ifelse with more than 2 conditions, it's often clearer to use a switch block. This reduces the potential for massive nested ifs, and should also discourage you from doing much branching within the if.

I don't really like how similar the summarise calls are in each case. Ideally I would refactor that, but I think that is somewhat tricky due to how dplyr handles n and n_distinct.

This is how I would rewrite your code, though I would also consult the tidyverse style guide to see their recommendations -- I generally try to avoid programming with dplyr so I'm not that familiar with the style.

filter_by_day_segment_refactor &lt;- function(data, day_segment) {
  ## Minimise the amount done within the if/else clause (also reduces duplication)
  if (day_segment == "daily") {
    fun &lt;- identity 
  } else {
    fun &lt;- function(x) filter(x, day_segment == local_day_segment)
  }
  data %&gt;% fun() %&gt;% group_by(local_date)
}

compute_metric_refactor &lt;- function(data, metric, day_segment) {
  ## 3 case switch block with just 1 pipe each, 
  ## rather than 3 conditionals with a mix of
  ## pipes and assignment
  switch(metric, 
    "countscans" = {
      data %&gt;% 
        filter_by_day_segment(day_segment) %&gt;%
        summarise(!!paste("sensor", day_segment, metric, sep = "_") := n())
    },
    "uniquedevices" = {
      data %&gt;%
        filter_by_day_segment(day_segment) %&gt;%
        summarise(!!paste("sensor", day_segment, metric, sep = "_") := n_distinct(value))
    },
    "countscansmostuniquedevice" = {
      data %&gt;% group_by(value) %&gt;% 
        mutate(N = n()) %&gt;% 
        ungroup() %&gt;%
        filter(N == max(N)) %&gt;%
        filter_by_day_segment(day_segment) %&gt;%
        summarise(!!paste("sensor", day_segment, metric, sep = "_") := n())
    }
  )
}