As a matter of long-standing policy, I avoid importing names into (aka "polluting") the current scope, and instead I use fully-qualified names when referring to items defined in a different package.
The script below shows that, in R, using qualified names is, in itself, not enough.
#!/usr/bin/env Rscript
set.seed(0)
x <- local({
x0 <- matrix(rnbinom(80, size = 5, mu = 10), nrow = 20)
`rownames<-`(rbind(0, c(0, 0, 2, 2), x0),
paste("Tag", 1:(nrow(x0) + 2), sep = "."))
})
y <- edgeR::DGEList(counts = x,
group = rep(1:2, each = 2),
lib.size = 1001:1004)
## library(edgeR)
y[1, 1]
The script fails with
Error in y[1, 1] : incorrect number of dimensions
Execution halted
The script's only crime appears to be not having included the line library(edgeR)
somewhere before the failing statement, since the error disappears if one un-comments the commented-out line.
This is voodoo, imho.
Is there a way to avoid the error without polluting the current scope with library(edgeR)
?