Hi,
the BiocChek gives a NOTE about NOTE: Consider clarifying how 9 object(s) are initialized. they are part of a data set loaded with data(), or perhaps part of an object referenced in with() or within(). function (object) codonmat2xy (Codon) codonmat2xy (syn) codonmat2xy (nonsyn) codonmat2xy (SynSum) codonmat2xy (NonSynSum) codonmat2xy (IndelSum) codonmat2xy (SynMean) codonmat2xy (NonSynMean) codonmat2xy (IndelMean)
However, the objects are initialized within a parallel foreach loop and than processed with dplyr.
Is there a way how to handle this kind of object initialization without getting a NOTE from BiocCheck?
Thank you in anticipation
Best regards
Kristian Ullrich
codonmat2xy <- function(codonmat, threads = 1){
doMC::registerDoMC(threads)
i <- NULL
j <- NULL
k <- NULL
OUT <- foreach(i = seq(from = 1, to = nrow(codonmat)), .combine=rbind) %dopar% {
foreach(j = seq(from = 1, to = ncol(codonmat) - 1), .combine=rbind) %do% {
foreach(k = seq(from = j + 1, to = ncol(codonmat)), .combine=rbind) %do% {
c(setNames(i, "Codon"),
setNames(j, "Comp1"),
setNames(k, "Comp2"),
setNames(compareCodons(codonmat[i, j], codonmat[i, k]), c("syn", "nonsyn", "indel")))
}
}
}
OUT <- as.data.frame(OUT)
OUT.NAs <- OUT %>% dplyr::group_by(Codon) %>% dplyr::filter(!is.na(syn)) %>%
dplyr::count(Codon)
OUT.SynSum <- OUT %>% dplyr::group_by(Codon) %>%
dplyr::summarise(SynSum = sum(syn, na.rm = TRUE))
OUT.NonSynSum <- OUT %>% dplyr::group_by(Codon) %>%
dplyr::summarise(NonSynSum = sum(nonsyn, na.rm = TRUE))
OUT.IndelSum <- OUT %>% dplyr::group_by(Codon) %>%
dplyr::summarise(IndelSum = sum(indel, na.rm = TRUE))
OUT.join <- dplyr::left_join(OUT.NAs, OUT.SynSum) %>%
dplyr::left_join(OUT.NonSynSum) %>% dplyr::left_join(OUT.IndelSum)
OUT.xy <- OUT.join %>% dplyr::mutate(SynMean = SynSum/n,
NonSynMean = NonSynSum/n,
IndelMean = IndelSum/n)
OUT.xy <- OUT.xy %>% dplyr::mutate(CumSumSynMean = cumsum(SynMean),
CumSumNonSynMean = cumsum(NonSynMean),
CumSumIndelMean = cumsum(IndelMean))
return(OUT.xy)
}
Thank you Marcel,
I could solve it by adding
#' @importFrom rlang .data
now the code looks like this: