To sort this list, the List of Lists a, you can try using sapply()the extract operator [[to retrieve data from the list. They are used when calling order():
a[order(sapply(a, `[[`, i = "day"))]
#[[1]]
#[[1]]$day
#[1] 1
#
#[[1]]$text
#[1] "bar"
#
#
#[[2]]
#[[2]]$day
#[1] 2
#
#[[2]]$text
#[1] "quux"
# ...
, sapply():
a[order(sapply(a, function(x) x$day))]
, , OP:
sortBy <- function(a, field) a[order(sapply(a, "[[", i = field))]
sortBy(a, "day")
, [[ .