0

I am pretty new using R, I have to program a new NMF algorithm to be used as the parameter method when the function nmf() is called.

As a way to start I would like to view the source code of the built-in algorithms as brunet, KL, lee, but I am unable to find it. Can someone help me please?

garfbradaz
  • 3,424
  • 7
  • 43
  • 70
Martha
  • 3
  • 2

3 Answers3

1

If you are using Rstudio, in R script you can hold Ctrl and click on the name of the function it jumps to the function source.

0

You can download the source here and then inspect the code for the function you are interested in. Additionally, try typing the name of the function at the console. If it is written in R you may see the whole function printed out. E.g.

f <- function(x) {return(x^2)}
f

function(x) {return(x^2)}

If the function is written in C/C++ it will give you information that it is compiled and you can look for the function in the downloaded source code, e.g.

head
function (x, ...) 
UseMethod("head")
<bytecode: 0x10a0d9158>
<environment: namespace:utils>
gfgm
  • 3,627
  • 14
  • 34
0
library(NMF)
showMethods("nmf")

Function: nmf (package NMF)
x="data.frame", rank="ANY", method="ANY"
x="formula", rank="ANY", method="ANY"
x="matrix", rank="data.frame", method="ANY"
x="matrix", rank="matrix", method="ANY"
x="matrix", rank="missing", method="ANY"
x="matrix", rank="NMF", method="ANY"
x="matrix", rank="NULL", method="ANY"
x="matrix", rank="numeric", method="character"
x="matrix", rank="numeric", method="function"
x="matrix", rank="numeric", method="list"
x="matrix", rank="numeric", method="missing"
x="matrix", rank="numeric", method="NMFStrategy"
x="matrix", rank="numeric", method="NULL"

Next select the method for which you want to see the source code as in

selectMethod("nmf", c("matrix", "matrix", "ANY"))
selectMethod("nmf", c("data.frame", "ANY", "ANY"))