title: How to enable breakpoint inside a function body when I debug the main Rscript
body: <p>I have a main R script which does a multiplication using a function called Multiply().</p>
  
  <pre><code>debugSource("C:/Users/R_debug_breakpoint/myFunction.R")
  a&lt;-1
  b&lt;-2
  mult&lt;-Multiply(a,b)
  </code></pre>
  
  <p>I write Multiply() in a different R script called "myFunction.R"</p>
  
  <p>"myFunction.R" looks like this:</p>
  
  <pre><code>Multiply&lt;-function(a,b){
    c&lt;-a+b
    e&lt;-a/b
    d&lt;-a*b
    return(d)
  }
  </code></pre>
  
  <p>If I want to set a breakpoint inside Multiply() function at the line:
  d&lt;-a*b and enter source mode to see what the value of c,e.</p>
  
  <p>However, when I press Source option in my main.R, the debugger does not halt at the breakpoint I set inside the Muliply function. It just runs all the codes in main.R.</p>
  
  <p>I search this problem in many webpages, and the most close one is 
  <a href="https://stackoverflow.com/questions/29512242/how-to-set-a-breakpoint-in-function-body-in-r-studio">How to set a breakpoint in function body in R-studio?</a></p>
  
  <p>However, I use debugSource here but it still fails.</p>
  
  <p>Another blog about the breakpoint I found out useful is:
  <a href="https://support.rstudio.com/hc/en-us/articles/200534337-Breakpoint-Troubleshooting" rel="nofollow noreferrer">https://support.rstudio.com/hc/en-us/articles/200534337-Breakpoint-Troubleshooting</a></p>
  
  <p>It says:In order to hit breakpoints during sourcing, you need to use the special debug sourcing command debugSource included in RStudio. If you are calling source manually on your file, breakpoints will still work, but will not be enabled until after all the code in the file has been executed.</p>
  
  <p>I think this is reason why it doesn't work, but it doesn't mention a work around for it.</p>
  
  <p>Much appreciated if any help from you guys.</p>