sprouffske / growthcurver

Growthcurver is an R package that fits growth curve data to a standard form of the logistic equation common in ecology and evolution whose parameters (the growth rate, the initial population size, and the carrying capacity) provide meaningful population-level information with straight-forward biological interpretation.
44 stars 14 forks source link

Small bug fix in the SummarizeGrowthByPlate function #1

Closed gauravdiwan89 closed 7 years ago

gauravdiwan89 commented 8 years ago

Hi,

I was using this package to analyze a few bacterial growth curves and I found a small bug in the SummarizeGrowthByPlate function. The function looks for a column titles 'time' and 'blank' and this is done using the grep function. The line of code is as follows:

if (sum(grep("time", names(plate), ignore.case = TRUE)) != 
        1) {
        stop("There must be exactly one column named 'time' in the 'plate' data.frame.", 
            call. = FALSE)

####
if (bg_correct == "blank") {
        if (sum(grep("blank", names(plate), ignore.case = TRUE)) != 
            1) {
            stop("There must be exactly one column named 'blank' in the 'plate' data.frame if you have selected the bg_correct 'plate' option.", 
                call. = FALSE)
        }
        names(plate)[grep("blank", names(plate), ignore.case = TRUE)] <- "blank"
    }

The current code is summing up the column number which have the entries 'time' and 'blank'. Thus, if the 'blank' column is the 2nd column in the data frame, the condition fails and the code is stopped. I suggest the following correction for both these lines:

if (length(grep("time", names(plate), ignore.case = TRUE)) != 
        1) {
        stop("There must be exactly one column named 'time' in the 'plate' data.frame.", 
            call. = FALSE)

####
if (bg_correct == "blank") {
        if (length(grep("blank", names(plate), ignore.case = TRUE)) != 
            1) {
            stop("There must be exactly one column named 'blank' in the 'plate' data.frame if you have selected the bg_correct 'plate' option.", 
                call. = FALSE)
        }
        names(plate)[grep("blank", names(plate), ignore.case = TRUE)] <- "blank"
    }

I have simply changed 'sum' to 'length'.

I think this will solve the issue.

Thanks!

Gaurav D

kieran-mace commented 7 years ago

I found this issue also! I have created a fix on a forked repo that I have made a pull request for.

While we wait for these changes to be made by the author, you can install the lightly modified version by using devtools::install_github('kmace/growthcurver')

sprouffske commented 7 years ago

Thanks for the bug fix! The code has been updated.