How to debug R code within a package

My R code fails within a 3rd party package. I would like to debug it to understand what exactly causes the code to fail (and possibly change my input parameters). Is there a way to do it?

The package I have a problem with is mgcv (function gam()).
It runs fine for some formulas I have and fails or takes forever with others.
I wonder if I can debug the code within the package to see where the code fails.

I know this is an old issue, but you can see the source code for R functions by typing the name of the function without the parenthesis. (so for gam(), you would just type gam)

You can then copy that code into your own script (I usually name it something similar like gam2 and debug/alter it as needed. It’s probably not the most elegant solution, but it has worked for me in the past.

1 Like

Yes, This is exactly the solution I found that worked for me!.Thank you.