I need to sort multiple dataframes by a list of columns with non-alphabetic characters in their names. For a single dataset I'd use this famous solution with a workaround for blanks and stuff in the variable name:
df_sorted = df[with(df, order(varname, xtfrm(df[,"varname with blanks and\slashes"]) ) ), ]
But for multiple datasets it's more suitable to have a function with a vector of column names as an input:
sort_by_columns = function(col_names){...}
df_sorted = sort_by_columns(col_names = c("varname","varname with blanks and\slashes"))
How do I transform a vector into an argument suitable for order()
inside my function?