idem-lab / syncomat

Synthetically generated contact matrices for 200 countries using the R package conmat
2 stars 1 forks source link

Which is better? `return(out_data)` vs just `out_data` in functions #17

Closed chitrams closed 5 months ago

chitrams commented 5 months ago

In the following function for example:

create_population_data <- function(in_data){

  # This function takes the list of countries,
  # and plugs it into as_conmat_population()
  # to create the population data.

  population_data <- map(
    .x = in_data,
    .f = \(x) as_conmat_population(
      data = x,
      age = lower.age.limit, 
      population = population))

  return(population_data)
}

Is it better to specify return(population_data) as above or simply to just put population_data at the end of that function? To research.

chitrams commented 5 months ago

return(out_data) is better practice because it explicitly defines what it is that you want out of the function. R can do just out_data or even without specification if in the above I didn't save it to the object population-data.