bhklab / CoreGx

Shared code for both PharmacoGx and RadioGx
https://bhklab.github.io/CoreGx/
GNU General Public License v3.0
2 stars 3 forks source link

Handle trailing commas via `...` in `aggregate2` method #166

Open ChristopherEeles opened 1 year ago

ChristopherEeles commented 1 year ago

Found this bug today but haven't figured out a fix yet.

When calling the aggregate2 function with a trailing comma in the function arguments the call that is parsed in:

# -- capture dots as a call and parse dot names, adding default names if
# --   they are missing
agg_call <- if (enlist) substitute(list(...)) else substitute(...)

When enlist=TRUE results in a call where the last item is a missing argument. However, there is no class or type indications that allow this to be easily caught. As a result when there is a trailing comma in the call the error ends up appearing when trying to use the dot_call variable:

for (i in which(dot_names == "")) {
    dot_call <- agg_call[[i + 1]]
    # assumes the first argument in a function call is always the column name!
    dot_names[i] <- paste0(dot_call[1:max(2, length(dot_call))], collapse="_")
}

Maybe we can at least handle this error in a try block or something? Not a priority right now but its obfuscated enough that I felt I should document it.

Chris