0

Some key algorithms are written with c/c++ in R. for example, in the package 'tree', the related code is as follows,

fit <- .C(BDRgrow1, as.double(X), as.double(unclass(Y)), 
    as.double(w), as.integer(c(sapply(xlevels, length), 
      length(ylevels))), as.integer(rep(1, nobs)), as.integer(nobs), 
    as.integer(ncol(X)), node = integer(control$nmax), var = integer(control$nmax), 
    cutleft = character(control$nmax), cutright = character(control$nmax), 
    n = double(control$nmax), dev = double(control$nmax), 
    yval = double(control$nmax), yprob = double(max(control$nmax * 
      length(ylevels), 1)), as.integer(control$minsize), 
    as.integer(control$mincut), as.double(max(0, control$mindev)), 
    nnode = as.integer(0L), where = integer(nobs), as.integer(control$nmax), 
    as.integer(split == "gini"), as.integer(sapply(m, is.ordered)), 
    NAOK = TRUE)

BDRgrow1 should be the name of a C function. how to read the source code of the function? Any help will be greatly appriciated.

wallace
  • 13
  • 3
  • see https://github.com/cran/tree/blob/072abb48a70057bc1424394c16bd74ba4a953884/src/tree.h#L20 – MichaelChirico Sep 29 '22 at 02:54
  • You can't have a "C/C++" function. It's either a "C" function or a "C++" function, they are different languages. In C++ you will have the added "problem" of name mangling. In C++ you would need to add an extern "C" interface. To read source code from C/C++ you will need its original sources since they are "lost" when the code is compiled to machine instructions. – Pepijn Kramer Sep 29 '22 at 03:55

0 Answers0