Problem: Some R package implements some functionality you want, but you just want to copy parts of that implementation. How do get access to the source?
Simply typing the name of the function in the R terminal prints out the source. For example I wanted to copy the implementation of the salience and distinctivness statistics calculated by the package LDAvis so after installing the package and finding out which function implemented this capability I typed
> createJSON function (phi = matrix(), theta = matrix(), doc.length = integer(), vocab = character(), term.frequency = integer(), R = 30, lambda.step = 0.01, mds.method = jsPCA, cluster, plot.opts = list(xlab = "PC1", ylab = "PC2"), ...) { dp <- dim(phi) dt <- dim(theta) N <- sum(doc.length) W <- length(vocab) D <- length(doc.length) K <- dt[2] [...]
Sometimes the packages use some "clever" mechanism so that what you get is only a wrapper, in that case look here https://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function.