Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>No function overloading + no object oriented = verbose function names.

Forgive me if I misunderstand, but are you saying R doesn't have function overloading? Because R's S3 class type system relies entirely on function overloading to make up for not having class-bound methods. Look at the result of `methods("print")` to see how overloaded that function is.

The real problem with this system is that every function is in the general namespace. It gets hard to avoid name clashes. Some packages have taken to appending prefixes to their function names (e.g., every function from the stringi package starts with "stri_").

>What I find even more crazy is that some of the R functions take function names as strings as argument. For example, taking "sum" as an argument will then apply the sum function to the dataframe.

Think of it like a "naturalized" macro language. When you know you'll always use `sum`, you can pass the function object itself. But character vectors are easier to deal with in logic and control flows. For a toy example, let's say you have a dataset with some columns that contain addresses, some that contain dates, and so on. You could write an overall cleaning function that takes the dataset and a "format" table to be a lookup between column names and functions to use¹. R even has `getFunction` to make this simple.

¹Because functions are regular objects in R, the format table could have a list column with the functions. But I've found my code looks more cluttered when using arbitrary functions in logic. And function names are easier to handle when saving data frames to files or databases.



Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: