Qfin
Qfin

Reputation: 39

Accessing the entire source code of a function that has "useMethod("packagefunction") in Rstudio?

I am trying to extend the functionality of a package and therefore trying to access the entire code behind one of the functions.

The package in question is RQuantLib and I am trying to see the entire code used in the function "DiscountCurve"

The result I get is simply:

function (params, tsQuotes, times = seq(0, 10, 0.1), legparams = list(dayCounter = "Thirty360", 
  fixFreq = "Annual", floatFreq = "Semiannual")) 
{
  UseMethod("DiscountCurve")
}

I have tried quite a few solutions as posted in this thread with no luck: How can I view the source code for a function?

UseMethod("DiscountCurve") does not tell me much. As far as I understand this is a translated package from C++. I am rather new to coding so it is possible that I have just not implemented the correct solution in the thread above correctly.

Edit for more detial on methods used so far: Results from methods: > methods("DiscountCurve") 1 DiscountCurve.default*

When checking methods(Class="default") I get 184 results. Due to space I will post screenshots of the code: prnt.sc/tws98x

Further using getAnywhere: prnt.sc/tws9rq

Upvotes: 2

Views: 754

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173793

If you do:

RQuantLib:::DiscountCurve.default

You will see the actual code that runs when the generic calls UseMethod("DiscountCurve") . However, you are likely to be disappointed, because essentially that function is a glorified type-checker which passes your parameters safely to another unexported function called discountCurveEngine, which looks like this:

RQuantLib:::discountCurveEngine
function (rparams, tslist, times, legParams) 
{
    .Call(`_RQuantLib_discountCurveEngine`, rparams, tslist, 
        times, legParams)
}

Which, you will see, is actually a thin wrapper for the C++ code that actually does the calculation. It is written in Rcpp-flavoured C++ and you can read the source code here. However, this in turn calls functions from another C++ library called Quantlib.

Depending on how keen you are, and how proficient you are in C++, you may find this enjoyably challenging or dishearteningly baffling, but at least you know where to find the source code.

Upvotes: 3

Related Questions