When I am debugging a piece of code I usually do it inside the R-terminal. It’s nice to do things this way because you can poke at things when something goes wrong. The only disadvantage is that you mush “refresh” the environment before re-executing. I used to quit and re-enter. I found a cool command that does what I want within the R environment:
rm(list = ls(all = TRUE))