Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BiocGenerics breaks template filling #337

Open
mschubert opened this issue Jan 13, 2025 · 0 comments
Open

BiocGenerics breaks template filling #337

mschubert opened this issue Jan 13, 2025 · 0 comments
Labels

Comments

@mschubert
Copy link
Owner

mschubert commented Jan 13, 2025

The following call to Q no longer works when loading the BiocGenerics library:

library(BiocGenerics) # remove this line and it works
res = clustermq::Q(identity, x=1, n_jobs=1, memory=1000)
# n_jobs gets filled as "   3"

The reason for this is that in fill_template, we do the following:

clustermq/R/util.r

Lines 35 to 37 in ec01add

is_num = sapply(values, is.numeric)
if (length(is_num) > 0)
values[is_num] = format(values[is_num], scientific=FALSE, trim=TRUE)

which boils down to:

format(list(a=3, b=1000), scientific=FALSE, trim=TRUE)
#     a      b
#   "3" "1000"

library(BiocGenerics)
format(list(a=3, b=1000), scientific=FALSE, trim=TRUE)
# [1] "   3" "1000"

because BiocGenerics provides a format.list, whereas base::format.default handles the list case with an if (is.list(x)). So the dispatch moves from base::format.default to BiocGenerics::format.list, which itself uses base::format.AsIs:

# https://github.com/Bioconductor/BiocGenerics/blob/devel/R/format.R#L29
format.list <- base::format.AsIs

# https://github.com/wch/r-source/blob/tags/R-4-4-2/src/library/base/R/format.R#L277-L292
format.AsIs <- function(x, width = 12, ...)
{
    ...
    format.default(rvec, justify = "right") # note the lack of passing '...', dropping trim=TRUE
}

A workaround is calling format.default explicitly in fill_template:

clustermq/R/util.r

Lines 35 to 37 in c7a0800

is_num = sapply(values, is.numeric)
if (length(is_num) > 0)
values[is_num] = format.default(values[is_num], scientific=FALSE, trim=TRUE)

mschubert added a commit that referenced this issue Jan 13, 2025
@mschubert mschubert added the bug label Jan 13, 2025
mschubert added a commit that referenced this issue Jan 13, 2025
mschubert added a commit that referenced this issue Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant