'n'go

A little addition to my LittleHelpers.
UPD. Now these functions are a part of my R package LittleHelpers.
savengo is ridiculously simple but very useful function that saves objects from a middle of your pipe and passes the same object to further elements of the pipe. It allows more efficient debugging and less confusing code, in which you don’t have to interrupt your pipe every time you need to save an output.
Its sister function appendngo appends an intermediary product to an existing list or a vector.
By analogy, one can create whatever storing function they need.

# Example 1
#Saves intermediary result to an object named intermediate.result
final.result <- dt %>% dplyr::filter(score<.5) %>%
                        savengo("intermediate.result") %>%
                        dplyr::filter(estimated<0)
# Example 2
#Saves intermediary result as a first element of existing list
final.result <- dt %>% dplyr::filter(score<.5) %>%
                        appendngo(myExistingList, after=0) %>%
                        dplyr::filter(estimated<0)

Leave a Reply

Your email address will not be published. Required fields are marked *