Contents

methods = 'KNN_IMPUTE,msImpute'
# Parameters
methods = "BPCA,COLMEDIAN,IMPSEQ,IMPSEQROB,IRM,KNN_IMPUTE,LLS,MINDET,MINIMUM,MINPROB,MLE,PI,QRILC,RF,ROWMEDIAN,SVDMETHOD,TRKNN,ZERO"

Hide code cell source

# options("install.lock"=FALSE)

packages_base_R <-
  c("BiocManager", "reshape2", "data.table", "readr", "tibble")

install_rpackage  <- function(pkg) {
  # If not installed, install the package
  if (!require(pkg, character.only = TRUE)) {
    install.packages(pkg)
    library(pkg, character.only = TRUE)
  }
  
}

# used in the large imputation function for two packages
install_bioconductor  <- function(pkg) {
  # If not installed, install the package
  if (!require(pkg, character.only = TRUE)) {
    BiocManager::install(pkg)
    library(pkg, character.only = TRUE)
  }
  
}


nafunctions <- function(method = "zero") {
  method <- tolower(method)
  if (method == "zero") {
  }
  else if (method == "minimum") {
  }
  else if (method == "colmedian") {
    install_rpackage('e1071')
  }
  else if (method == "rowmedian") {
    install_rpackage('e1071')
  }
  else if (method == "knn_impute") {
    install_bioconductor('impute')
  }
  else if (method == "seqknn") {
    if (!require(SeqKnn)) {
      install.packages("src/R_NAGuideR/SeqKnn_1.0.1.tar.gz",
                       repos = NULL,
                       type = "source")
    }
  }
  else if (method == "bpca") {
    install_bioconductor('pcaMethods')
  }
  else if (method == "svdmethod") {
    install_bioconductor('pcaMethods')
  }
  else if (method == "lls") {
    install_bioconductor('pcaMethods')
  }
  else if (method == "mle") {
    install_rpackage('norm')
  }
  else if (method == "qrilc") {
    install_bioconductor("impute")
    install_bioconductor("pcaMethods")
    install_rpackage('gmm')
    install_rpackage('imputeLCMD')
  }
  else if (method == "mindet") {
    install_bioconductor("impute")
    install_bioconductor("pcaMethods")
    install_rpackage('gmm')
    install_rpackage('imputeLCMD')
  }
  else if (method == "minprob") {
    install_bioconductor("impute")
    install_bioconductor("pcaMethods")
    install_rpackage('gmm')
    install_rpackage('imputeLCMD')
  }
  else if (method == "irm") {
    install_rpackage('VIM')
  }
  else if (method == "impseq") {
    install_rpackage('rrcovNA')
  }
  else if (method == "impseqrob") {
    install_rpackage('rrcovNA')
  }
  else if (method == "mice-norm") {
    install_rpackage('mice')
  }
  else if (method == "mice-cart") {
    install_rpackage('mice')
  }
  else if (method == "trknn") {
    source('src/R_NAGuideR/Imput_funcs.r')
  }
  else if (method == "rf") {
    install_rpackage("missForest")
  }
  else if (method == "pi") {
  }
  # else if(method=="grr"){
  #   library(DreamAI)
  #   df<-impute.RegImpute(data=as.matrix(df1), fillmethod = "row_mean", maxiter_RegImpute = 10,conv_nrmse = 1e-03)
  # }
  else if (method == "gms") {
    # install.packages('GMSimpute')
    if (!require(GMSimpute)) {
      install.packages(
        "src/R_NAGuideR/GMSimpute_0.0.1.1.tar.gz",
        repos = NULL,
        type = "source"
      )
      }
  }
  else if (method == "msimpute") {
    install_bioconductor("msImpute")
  }
  else if (method == "msimpute_mnar") {
    install_bioconductor("msImpute")
  }
  else if (method == "gsimp") {
    options(stringsAsFactors = F)
    # dependencies parly for sourced file
    
    install_bioconductor("impute")
    install_bioconductor("pcaMethods")
    install_rpackage('gmm')
    install_rpackage('imputeLCMD')
    install_rpackage("magrittr")
    install_rpackage("glmnet")
    install_rpackage("abind")
    install_rpackage("foreach")
    install_rpackage("doParallel")
    source('src/R_NAGuideR/GSimp.R')
    
    } 
  else{
    stop(paste("Unspported methods so far: ", method))
  }
  df <- as.data.frame(df)
  df
}


for (package in packages_base_R) {
  # Check if the package is already installed
  install_rpackage(pkg = package)
}

if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
Loading required package: BiocManager
Warning message in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
“there is no package called ‘BiocManager’”
Updating HTML index of packages in '.Library'
Making 'packages.html' ...
 done
Loading required package: reshape2
Loading required package: data.table

Attaching package: ‘data.table’
The following objects are masked from ‘package:reshape2’:

    dcast, melt
Loading required package: readr
Loading required package: tibble
methods = unlist(strsplit(methods, split = ","))
for (package in methods) {
  # Check if the package is already installed, otherwise install
  nafunctions(method = package)
}
Loading required package: pcaMethods
Warning message in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
“there is no package called ‘pcaMethods’”
'getOption("repos")' replaces Bioconductor standard repositories, see
'help("repositories", package = "BiocManager")' for details.
Replacement repositories:
    CRAN: https://cran.r-project.org
Bioconductor version 3.22 (BiocManager 1.30.26), R 4.5.1 (2025-06-13)
Installing package(s) 'BiocVersion', 'pcaMethods'
also installing the dependencies ‘Biobase’, ‘BiocGenerics’
Updating HTML index of packages in '.Library'
Making 'packages.html' ...
 done
Old packages: 'gower', 'igraph', 'VIM'
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: generics

Attaching package: ‘generics’
The following objects are masked from ‘package:base’:

    as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
    setequal, union

Attaching package: ‘BiocGenerics’
The following objects are masked from ‘package:stats’:

    IQR, mad, sd, var, xtabs
The following objects are masked from ‘package:base’:

    anyDuplicated, aperm, append, as.data.frame, basename, cbind,
    colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
    get, grep, grepl, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, saveRDS, table, tapply, unique,
    unsplit, which.max, which.min
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Attaching package: ‘pcaMethods’
The following object is masked from ‘package:stats’:

    loadings
Loading required package: e1071

Attaching package: ‘e1071’
The following object is masked from ‘package:generics’:

    interpolate
Loading required package: rrcovNA
Warning message in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
“there is no package called ‘rrcovNA’”
Updating HTML index of packages in '.Library'
Making 'packages.html' ...
 done
Loading required package: rrcov
Loading required package: robustbase

Attaching package: ‘robustbase’
The following object is masked from ‘package:Biobase’:

    rowMedians
Scalable Robust Estimators with High Breakdown Point (version 1.7-7)
Scalable Robust Estimators with High Breakdown Point for
Incomplete Data (version 0.5-3)
Loading required package: VIM
Loading required package: colorspace
Loading required package: grid
VIM is ready to use.
Suggestions and bug-reports can be submitted at: https://github.com/statistikat/VIM/issues

Attaching package: ‘VIM’
The following object is masked from ‘package:datasets’:

    sleep
Loading required package: impute
Warning message in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
“there is no package called ‘impute’”
'getOption("repos")' replaces Bioconductor standard repositories, see
'help("repositories", package = "BiocManager")' for details.
Replacement repositories:
    CRAN: https://cran.r-project.org
Bioconductor version 3.22 (BiocManager 1.30.26), R 4.5.1 (2025-06-13)
Installing package(s) 'impute'
Updating HTML index of packages in '.Library'
Making 'packages.html' ...
 done
Old packages: 'gower', 'igraph', 'VIM'
Loading required package: gmm
Loading required package: sandwich

Attaching package: ‘sandwich’
The following object is masked from ‘package:generics’:

    estfun
Loading required package: imputeLCMD
Warning message in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
“there is no package called ‘imputeLCMD’”
Updating HTML index of packages in '.Library'
Making 'packages.html' ...
 done
Loading required package: tmvtnorm
Loading required package: mvtnorm
Loading required package: Matrix
Loading required package: stats4
Loading required package: norm
This package has some major limitations
(for example, it does not work reliably when
the number of variables exceeds 30),
and has been superseded by the norm2 package.
Loading required package: missForest

Attaching package: ‘missForest’
The following object is masked from ‘package:VIM’:

    nrmse