In the past I used to make use of
source(my_source_file, echo = TRUE, prompt = "") to “tidy up” my code because it’s not convenient for me to type every space between operators, what’s more, I have no fixed rules to break a line or make a proper indent. Thus I need a function to automatically “tidy up” my code.
After I read the source code of the function
source(), I quickly found that the actual workhorse is
parse(), which can turn your code file into neat expressions, and the rest work is just to extract substrings. Here is a proof of concept: