Can the code of a R package be changed? How?
1
1
Entering edit mode
9.4 years ago

I am using limma, and in representing a volcano plot, it turn out that the gene systematic gene I want to highlight is truncated..

If I revise the code (shown below) I can see that the highlighted gene comes from a substring with a maximum of 8 digits.

This observation lead me to ask if it is possible to make minor changes in the code present in the R package, and how this can be accomplished.

In my case, I can change all the systematic gene names, or change that 8 by a different value

> volcanoplot
function (fit, coef = 1, highlight = 0, names = fit$genes$ID, 
    xlab = "Log Fold Change", ylab = "Log Odds", pch = 16, cex = 0.35, 
    ...) 
{
    if (!is(fit, "MArrayLM")) 
        stop("fit must be an MArrayLM")
    if (is.null(fit$lods)) 
        stop("No B-statistics found, perhaps eBayes() not yet run")
    x <- as.matrix(fit$coef)[, coef]
    y <- as.matrix(fit$lods)[, coef]
    plot(x, y, xlab = xlab, ylab = ylab, pch = pch, cex = cex, 
        ...)
    if (highlight > 0) {
        if (is.null(names)) 
            names <- 1:length(x)
        names <- as.character(names)
        o <- order(y, decreasing = TRUE)
        I <- o[1:highlight]
        text(x[i], y[i], labels = substring(names[i], 1, 8), 
            cex = 0.8, col = "blue")
    }
    invisible()
}
<environment: namespace:limma>
R • 34k views
ADD COMMENT
3
Entering edit mode
9.4 years ago

You can always have the source and can directly change the files. Either repack and install the custom new package via command line

R CMD INSTALL package

or use the powerful updated editing capabilities within R. Check for function trace

Check this post on SO for more options.

ADD COMMENT
2
Entering edit mode

You can also use the devtools package for easier debugging.

First, install the devtools and load it with library(devtools). Then, activate the development mode with dev_mode(). This will allow you to recompile and reinstall new packages without altering your main R installation. Then, use install_local("path to modified limma package") to install it again.

ADD REPLY
0
Entering edit mode

This answer fulfill everything I need and even more. Thank you

ADD REPLY
1
Entering edit mode

If that's the case, please mark the answer as accepted. That way the respondent gets credit and other readers can see this question has a satisfactory answer already.

ADD REPLY
0
Entering edit mode

Hello,

I read this thread and I found it really useful. I am going to modify an r package too. I was wondering how can I recompile it through Rstudio. I have downloaded the source code of package and I have modified it. I am not sure how to source it or recompile it in Rstudio?

Thanks for your help

ADD REPLY
0
Entering edit mode

I don't think you can permanently change and/or compile a package using RStudio.. There are many books and references in the web to learn about it

ADD REPLY

Login before adding your answer.

Traffic: 1860 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6