rpackagegbm

R: how can I find C/C++ source code from the gbm package?


library(gbm)
gbm.fit

I ran the above code to see the source code for gbm.fit. And it looks like the "meat" of the function is in this line:

gbm.obj <- .Call("gbm_fit", Y = as.double(y), Offset = as.double(offset), 
                   X = as.double(x), X.order = as.integer(x.order), weights = as.double(w), 
                   Misc = as.double(Misc), cRows = as.integer(cRows), cCols = as.integer(cCols), 
                   var.type = as.integer(var.type), var.monotone = as.integer(var.monotone), 
                   distribution = as.character(distribution.call.name), 
                   n.trees = as.integer(n.trees), interaction.depth = as.integer(interaction.depth), 
                   n.minobsinnode = as.integer(n.minobsinnode), n.classes = as.integer(nClass), 
                   shrinkage = as.double(shrinkage), bag.fraction = as.double(bag.fraction), 
                   nTrain = as.integer(nTrain), fit.old = as.double(NA), 
                   n.cat.splits.old = as.integer(0), n.trees.old = as.integer(0), 
                   verbose = as.integer(verbose), PACKAGE = "gbm")

To my knowledge, .Call is passing an R object into C/C++ code. Am I right that there is a C/C++ function called gbm_fit? Where exactly can I find this source code? I've tried poking around https://rdrr.io/cran/gbm/src/R/gbm.fit.R, but I can't seem the find the actual source code for the C/C++ function. I also downloaded "gbm_2.1.8.tgz" but could not find the source code.


Solution

  • The source for the function gbm_fit is in src/gbmentry.cpp in the file gbm-2.1.8.tar.gz (Not the tgz file; that is the macOS binary). This file can be viewed online on GitHub.