Let's say I have a list of filenames and I want to write a function to, for each filename, import the file and clean it. This is a natural use of lapply, along the lines of
If the goal is to inspect the objects in the case of an error, you can set options(error = recover). In the event of an error, this setting allows you to choose a frame of the call stack to enter using the symbolic debugger.
If you run debug(cleaning_function), you will be entered into the function environment to interactively debug the next time the function cleaning_function() is executed. You can stop it by running undebug(cleaning_function) (or restarting your R session). The alternative debugonce() is similar, but it will only enter the debugger the first time the function is called.
browser()
You can stick browser() anywhere in the function to enter the debugger, e.g. the code below will enter you into the debugger whenever df doesn't have a column named old_id: