#!/bin/bash -ex

# Script for installing R from source
# To achieve an optimal build, add the necessary flags to ./configure in this script.
# See: https://stackoverflow.com/questions/8343686/how-to-install-2-different-r-versions-on-debian#comment10292265_8344873
#
# Resources:
#
# https://raw.githubusercontent.com/DominikMueller64/install_R_source/master/install_R_source.sh
# https://stackoverflow.com/questions/8343686/how-to-install-2-different-r-versions-on-debian
# https://stackoverflow.com/questions/24019503/installing-multiple-versions-of-r
# https://support.rstudio.com/hc/en-us/articles/215488098-Installing-multiple-versions-of-R
# http://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installation

R_VERSION=$1
R_VERSION_HOME="/usr/local/R/${R_VERSION}"

# Create temporary directory
mkdir -p $HOME/R_tmp
cd $HOME/R_tmp

function installR() {
	# Download and extract R source
	echo Downloading R source for ${R_VERSION}
	R_MAJOR=$(echo $R_VERSION | head -c 1)
	wget -q https://cran.r-project.org/src/base/R-${R_MAJOR}/R-${R_VERSION}.tar.gz
	tar xzf R-${R_VERSION}.tar.gz
	rm R-${R_VERSION}.tar.gz

	# Configure and make
	cd R-${R_VERSION}
	# some graphic packages require tcltk so it needs to be configured here
	./configure --prefix=${R_VERSION_HOME} --with-x=no --enable-R-shlib=yes --with-tcltk=yes \
				--with-tk-config=/usr/lib/tkConfig.sh --with-tcl-config=/usr/lib/tclConfig.sh
	make
	make install

	# R4.0 uses just lib R3.5 uses lib64
	mkdir -p ${R_VERSION_HOME}/lib/R/library || true
	mkdir -p ${R_VERSION_HOME}/lib64/R/library || true
	chmod a+w -R ${R_VERSION_HOME}/lib/R/library
	chmod a+w -R ${R_VERSION_HOME}/lib64/R/library

	# Cleanup
	cd ../..
	rm -rf $HOME/R_tmp

	# Create symbolic link
	ln -s ${R_VERSION_HOME}/bin/R /usr/bin/R-${R_VERSION}
	ln -s ${R_VERSION_HOME}/bin/Rscript /usr/bin/Rscript-${R_VERSION}
	echo The R-${R_VERSION} executable is now available in /usr/bin/R-${R_VERSION}

	# Create dirs for current R and make them writable
	mkdir -p /usr/local/R/current/bin/
	chmod a+w /usr/local/R/current/bin/

	echo "Generate activate script"
	# Create activation script
	echo """#! /bin/bash

ln -s -f ${R_VERSION_HOME}/bin/R /usr/local/R/current/bin/R
ln -s -f ${R_VERSION_HOME}/bin/Rscript /usr/local/R/current/bin/Rscript""" > /usr/bin/activate_R_${R_VERSION}
	chmod a+x /usr/bin/activate_R_${R_VERSION}
}

installR

# Activate this R version
echo "Activating R ${R_VERSION}"
activate_R_${R_VERSION}


function header() {
	set +x
	echo
	echo $*
	echo $* | sed -e 's/./=/g'
	set -x
}

function checkRInstallLog() {
	log_file=$1
	if grep -E '(packages .* are not available)|(installation of package .* had non-zero exit status|ERROR: dependenc.*not available for package)' $log_file; then
		echo "Errors detected in R package installation."
		exit 1
	fi
}

function getAndInstall() {
	NAME="$2"
	VERSION="$3"
	if isAlreadyPresent "$NAME" "$VERSION" ; then
		echo ":: " Package $NAME with version $VERSION or above is already present. Skipping installation.
	else
		header Downloading $2
		wget "$1" -O "$2.tar.gz" || return 1
		header Installing $2
		/usr/local/R/current/bin/R CMD INSTALL  "$2.tar.gz"  2>&1 | tee "$2.log"
		checkRInstallLog "$2.log"
		rm  "$2.tar.gz" "$2.log"
		isAlreadyPresent "$NAME" "$VERSION" || exit 1  # make sure it's installed
	fi
}

function isAlreadyPresent(){
	NAME="$1"
	VERSION="$2"
	/usr/local/R/current/bin/R -q -e "if (require('$NAME') &&\
   utils::compareVersion('$VERSION', as.character(packageVersion('$NAME'))) <= 0) q('no', 0) else q('no', 1)" &> /dev/null
}


function getAndInstallFromCRAN(){
	set +x
	NAME="$1"
	VERSION="$2"
	getAndInstall "https://cran.r-project.org/src/contrib/Archive/${NAME}/${NAME}_${VERSION}.tar.gz" "$NAME" "$VERSION" || \
		getAndInstall "https://cran.r-project.org/src/contrib/${NAME}_${VERSION}.tar.gz" "$NAME" "$VERSION" || \
		getAndInstall "https://cloud.r-project.org/src/contrib/Archive/${NAME}/${NAME}_${VERSION}.tar.gz" "$NAME" "$VERSION" || exit 1
	set -x
}

# How to get dependencies?
#=========================
# Since we can't rely on `versions` package to get older packages (Microsoft's CRAN (MRAN) is discontinued), we have to
# install the packages in some other way. What I did was opened the dev-r-3.3.3-jdk-8 and got the installed packages by
# using the following:
#
########################################################################################################################
# # Get packages and freeze them
# write.csv(installed.packages(), "pkgs.csv")
########################################################################################################################
#
# Now that I got the packages, their versions and their dependencies, I am able to topologically sort them to ensure
# I won't try to install a package that has is missing some dependencies. Then I install it from CRAN using the above
# defined shell function `getAndInstallFromCRAN`.
#
# To make it repeatable I created the following script in R that uses `igraph` package for creating the graph representing
# packages and its dependencies that are then topologically sorted and printed out so it can be easily copy-pasted here.
# Some packages may never reach CRAN and those should be added to the exclude_pkgs vector (like the `isofor` package)
# and then installed separately.
#
########################################################################################################################
# exclude_pkgs <- c("isofor")
#
# # Load them, sort them topologically and generate the code to install them
# pkgs <- read.csv("/Users/tomasfryda/tmp/jenkins_logs/pkgs.csv")
# pkgs <- pkgs[pkgs$Priority != "base" | is.na(pkgs$Priority),]
# rownames(pkgs) <- pkgs$Package
#
# library(igraph)
#
# i2n <- setNames(pkgs$Package, seq_len(nrow(pkgs)))
# n2i <- setNames(names(i2n), i2n)
#
# g <- make_empty_graph(directed = TRUE)
# g <- add_vertices(g, nrow(pkgs), label = i2n)
#
# for (n in i2n) {
#   deps <- paste0(pkgs[n, "Depends"], ", ", pkgs[n, "Imports"])
#   cat(n, "->", deps, "\n")
#   if (is.na(deps))
#     next
#   deps <- strsplit(deps, ",\\s*", perl = TRUE)[[1]]
#   for (d in deps) {
#     print(d)
#     d <- strsplit(d, "\\s+", perl = TRUE)[[1]][[1]]
#     print(d)
#     if (d %in% i2n) {
#       g <- add_edges(g, c(n2i[[n]], n2i[[d]]))
#     }
#   }
# }
#
# ts <- topo_sort(g, mode = "in")
# ts <- ts[!ts %in% n2i[exclude_pkgs]]
# cat(paste("getAndInstallFromCRAN", i2n[ts], pkgs[i2n[ts], "Version"]), sep = "\n")
########################################################################################################################


# Install dependencies
echo "Installing dependencies for R ${R_VERSION}"

if [ "$R_VERSION" = "4.5.2" ]; then
	getAndInstallFromCRAN AUC 0.3.2
	getAndInstallFromCRAN DEoptimR 1.1-4
	getAndInstallFromCRAN Formula 1.2-5
	getAndInstallFromCRAN HDtweedie 1.2
	getAndInstallFromCRAN KernSmooth 2.23-26
	getAndInstallFromCRAN LiblineaR 2.10-24
	getAndInstallFromCRAN MASS 7.3-65
	getAndInstallFromCRAN R.methodsS3 1.8.2
	getAndInstallFromCRAN R6 2.6.1
	getAndInstallFromCRAN RColorBrewer 1.1-3
	getAndInstallFromCRAN RUnit 0.4.33.1
	getAndInstallFromCRAN Rcpp 1.1.0
	getAndInstallFromCRAN RcppParallel 5.1.11-1
	getAndInstallFromCRAN RhpcBLASctl 0.23-42
	getAndInstallFromCRAN S7 0.2.1
	getAndInstallFromCRAN SparseM 1.84-2
	getAndInstallFromCRAN abind 1.4-8
	getAndInstallFromCRAN acepack 1.6.3
	getAndInstallFromCRAN backports 1.5.0
	getAndInstallFromCRAN base64enc 0.1-3
	getAndInstallFromCRAN bit 4.6.0
	getAndInstallFromCRAN bitops 1.0-9
	getAndInstallFromCRAN boot 1.3-32
	getAndInstallFromCRAN brew 1.0-10
	getAndInstallFromCRAN brio 1.1.5
	getAndInstallFromCRAN cli 3.6.5
	getAndInstallFromCRAN clipr 0.8.0
	getAndInstallFromCRAN cluster 2.1.8.1
	getAndInstallFromCRAN codetools 0.2-20
	getAndInstallFromCRAN colorspace 2.1-2
	getAndInstallFromCRAN commonmark 2.0.0
	getAndInstallFromCRAN cpp11 0.5.2
	getAndInstallFromCRAN crayon 1.5.3
	getAndInstallFromCRAN curl 7.0.0
	getAndInstallFromCRAN data.table 1.17.8
	getAndInstallFromCRAN deldir 2.0-4
	getAndInstallFromCRAN digest 0.6.39
	getAndInstallFromCRAN diptest 0.77-2
	getAndInstallFromCRAN evaluate 1.0.5
	getAndInstallFromCRAN fansi 1.0.7
	getAndInstallFromCRAN farver 2.1.2
	getAndInstallFromCRAN fastmap 1.2.0
	getAndInstallFromCRAN float 0.3-3
	getAndInstallFromCRAN foreign 0.8-90
	getAndInstallFromCRAN formatR 1.14
	getAndInstallFromCRAN fs 1.6.6
	getAndInstallFromCRAN futile.options 1.0.1
	getAndInstallFromCRAN generics 0.1.4
	getAndInstallFromCRAN getopt 1.20.4
	getAndInstallFromCRAN gitcreds 0.1.2
	getAndInstallFromCRAN glue 1.8.0
	getAndInstallFromCRAN gtools 3.9.5
	getAndInstallFromCRAN highlight 0.5.1
	getAndInstallFromCRAN ini 0.3.1
	getAndInstallFromCRAN isoband 0.2.7
	getAndInstallFromCRAN iterators 1.0.14
	getAndInstallFromCRAN jpeg 0.1-11
	getAndInstallFromCRAN jsonlite 2.0.0
	getAndInstallFromCRAN kernlab 0.9-33
	getAndInstallFromCRAN labeling 0.4.3
	getAndInstallFromCRAN lattice 0.22-7
	getAndInstallFromCRAN lazyeval 0.2.2
	getAndInstallFromCRAN magrittr 2.0.4
	getAndInstallFromCRAN matrixStats 1.5.0
	getAndInstallFromCRAN mclust 6.1.2
	getAndInstallFromCRAN mime 0.13
	getAndInstallFromCRAN misc3d 0.9-1
	getAndInstallFromCRAN mlbench 2.1-6
	getAndInstallFromCRAN modeltools 0.2-24
	getAndInstallFromCRAN mvtnorm 1.3-3
	getAndInstallFromCRAN nnet 7.3-20
	getAndInstallFromCRAN otel 0.2.0
	getAndInstallFromCRAN packrat 0.9.3
	getAndInstallFromCRAN pixmap 0.4-14
	getAndInstallFromCRAN pkgconfig 2.0.3
	getAndInstallFromCRAN png 0.1-8
	getAndInstallFromCRAN praise 1.0.0
	getAndInstallFromCRAN prettyunits 1.2.0
	getAndInstallFromCRAN proxy 0.4-27
	getAndInstallFromCRAN ps 1.9.1
	getAndInstallFromCRAN randomForest 4.7-1.2
	getAndInstallFromCRAN rappdirs 0.3.3
	getAndInstallFromCRAN remotes 2.5.0
	getAndInstallFromCRAN renv 1.1.5
	getAndInstallFromCRAN rlang 1.1.6
	getAndInstallFromCRAN rpart 4.1.24
	getAndInstallFromCRAN rprojroot 2.1.1
	getAndInstallFromCRAN rstudioapi 0.17.1
	getAndInstallFromCRAN shape 1.4.6.1
	getAndInstallFromCRAN slam 0.1-55
	getAndInstallFromCRAN sourcetools 0.1.7-1
	getAndInstallFromCRAN sparsepp 1.22
	getAndInstallFromCRAN spatial 7.3-18
	getAndInstallFromCRAN statmod 1.5.1
	getAndInstallFromCRAN stringi 1.8.7
	getAndInstallFromCRAN svd 0.5.8
	getAndInstallFromCRAN sys 3.4.3
	getAndInstallFromCRAN tweedie 2.3.5
	getAndInstallFromCRAN utf8 1.2.6
	getAndInstallFromCRAN uuid 1.2-1
	getAndInstallFromCRAN versions 0.3
	getAndInstallFromCRAN viridisLite 0.4.2
	getAndInstallFromCRAN whisker 0.4.1
	getAndInstallFromCRAN withr 3.0.2
	getAndInstallFromCRAN xfun 0.54
	getAndInstallFromCRAN xtable 1.8-4
	getAndInstallFromCRAN yaml 2.3.10
	getAndInstallFromCRAN zip 2.3.3
	getAndInstallFromCRAN robustbase 0.99-6
	getAndInstallFromCRAN class 7.3-23
	getAndInstallFromCRAN R.oo 1.27.1
	getAndInstallFromCRAN lgr 0.5.0
	getAndInstallFromCRAN RcppArmadillo 15.2.2-1
	getAndInstallFromCRAN RcppEigen 0.3.4.0.2
	getAndInstallFromCRAN RcppTOML 0.2.3
	getAndInstallFromCRAN checkmate 2.3.3
	getAndInstallFromCRAN PKI 0.1-15
	getAndInstallFromCRAN bit64 4.6.0-1
	getAndInstallFromCRAN RCurl 1.98-1.17
	getAndInstallFromCRAN caTools 1.18.3
	getAndInstallFromCRAN desc 1.4.3
	getAndInstallFromCRAN sessioninfo 1.2.3
	getAndInstallFromCRAN munsell 0.5.1
	getAndInstallFromCRAN diffobj 0.3.6
	getAndInstallFromCRAN rversions 3.0.0
	getAndInstallFromCRAN interp 1.1-6
	getAndInstallFromCRAN lambda.r 1.2.4
	getAndInstallFromCRAN optparse 1.7.5
	getAndInstallFromCRAN foreach 1.5.2
	getAndInstallFromCRAN Matrix 1.7-4
	getAndInstallFromCRAN nlme 3.1-168
	getAndInstallFromCRAN sp 2.2-0
	getAndInstallFromCRAN zoo 1.8-14
	getAndInstallFromCRAN prabclus 2.3-4
	getAndInstallFromCRAN plot3D 1.4.2
	getAndInstallFromCRAN libcoin 1.0-10
	getAndInstallFromCRAN flexmix 2.3-20
	getAndInstallFromCRAN processx 3.8.6
	getAndInstallFromCRAN cachem 1.1.0
	getAndInstallFromCRAN ellipsis 0.3.2
	getAndInstallFromCRAN htmltools 0.5.8.1
	getAndInstallFromCRAN later 1.4.4
	getAndInstallFromCRAN lifecycle 1.0.4
	getAndInstallFromCRAN xml2 1.5.0
	getAndInstallFromCRAN askpass 1.2.1
	getAndInstallFromCRAN highr 0.11
	getAndInstallFromCRAN tinytex 0.58
	getAndInstallFromCRAN e1071 1.7-16
	getAndInstallFromCRAN flexclust 1.5.0
	getAndInstallFromCRAN R.utils 2.13.0
	getAndInstallFromCRAN gplots 3.2.0
	getAndInstallFromCRAN waldo 0.6.2
	getAndInstallFromCRAN latticeExtra 0.6-31
	getAndInstallFromCRAN futile.logger 1.4.3
	getAndInstallFromCRAN MatrixExtra 0.1.15
	getAndInstallFromCRAN irlba 2.3.5.1
	getAndInstallFromCRAN mlapi 0.1.1
	getAndInstallFromCRAN survival 3.8-3
	getAndInstallFromCRAN xgboost 1.7.11.1
	getAndInstallFromCRAN mgcv 1.9-4
	getAndInstallFromCRAN ade4 1.7-23
	getAndInstallFromCRAN sandwich 3.1-1
	getAndInstallFromCRAN fpc 2.2-13
	getAndInstallFromCRAN callr 3.7.6
	getAndInstallFromCRAN xopen 1.0.1
	getAndInstallFromCRAN memoise 2.0.1
	getAndInstallFromCRAN crosstalk 1.2.2
	getAndInstallFromCRAN fontawesome 0.5.3
	getAndInstallFromCRAN jquerylib 0.1.4
	getAndInstallFromCRAN sass 0.4.10
	getAndInstallFromCRAN gtable 0.3.6
	getAndInstallFromCRAN promises 1.5.0
	getAndInstallFromCRAN scales 1.4.0
	getAndInstallFromCRAN systemfonts 1.3.1
	getAndInstallFromCRAN vctrs 0.6.5
	getAndInstallFromCRAN urlchecker 1.0.1
	getAndInstallFromCRAN openssl 2.3.4
	getAndInstallFromCRAN knitr 1.50
	getAndInstallFromCRAN ROCR 1.0-11
	getAndInstallFromCRAN rsparse 0.5.3
	getAndInstallFromCRAN TH.data 1.1-5
	getAndInstallFromCRAN gbm 2.1.9  # version 2.2.2 gives slightly different results
	getAndInstallFromCRAN glmnet 4.1-10
	getAndInstallFromCRAN penalized 0.9-53
	getAndInstallFromCRAN pkgbuild 1.4.8
	getAndInstallFromCRAN webshot 0.5.5
	getAndInstallFromCRAN bslib 0.9.0
	getAndInstallFromCRAN gridExtra 2.3
	getAndInstallFromCRAN httpuv 1.6.16
	getAndInstallFromCRAN textshaping 1.0.4
	getAndInstallFromCRAN downlit 0.4.5
	getAndInstallFromCRAN ggplot2 4.0.1
	getAndInstallFromCRAN pillar 1.11.1
	getAndInstallFromCRAN purrr 1.2.0
	getAndInstallFromCRAN stringr 1.6.0
	getAndInstallFromCRAN tidyselect 1.2.1
	getAndInstallFromCRAN credentials 2.0.3
	getAndInstallFromCRAN httr 1.4.7
	getAndInstallFromCRAN httr2 1.2.1
	getAndInstallFromCRAN jose 1.2.1
	getAndInstallFromCRAN tables 0.9.31
	getAndInstallFromCRAN MLmetrics 1.1.3
	getAndInstallFromCRAN text2vec 0.6.4
	getAndInstallFromCRAN multcomp 1.4-29
	getAndInstallFromCRAN pkgload 1.4.1
	getAndInstallFromCRAN rcmdcheck 1.4.0
	getAndInstallFromCRAN rmarkdown 2.30
	getAndInstallFromCRAN shiny 1.11.1
	getAndInstallFromCRAN ragg 1.5.0
	getAndInstallFromCRAN viridis 0.6.5
	getAndInstallFromCRAN repr 1.1.7
	getAndInstallFromCRAN tibble 3.3.0
	getAndInstallFromCRAN gert 2.2.0
	getAndInstallFromCRAN gh 1.5.0
	getAndInstallFromCRAN snowflakeauth 0.2.0
	getAndInstallFromCRAN coin 1.4-3
	getAndInstallFromCRAN roxygen2 7.3.3
	getAndInstallFromCRAN testthat 3.3.1
	getAndInstallFromCRAN htmlwidgets 1.6.4
	getAndInstallFromCRAN miniUI 0.1.2
	getAndInstallFromCRAN shinyjs 2.1.0
	getAndInstallFromCRAN IRdisplay 1.1
	getAndInstallFromCRAN dplyr 1.1.4
	getAndInstallFromCRAN pkgdown 2.2.0
	getAndInstallFromCRAN rematch2 2.1.2
	getAndInstallFromCRAN usethis 3.2.1
	getAndInstallFromCRAN rsconnect 1.6.2
	getAndInstallFromCRAN DT 0.34.0
	getAndInstallFromCRAN htmlTable 2.4.3
	getAndInstallFromCRAN profvis 0.4.0
	getAndInstallFromCRAN rgl 1.3.31
	getAndInstallFromCRAN tidyr 1.3.1
	getAndInstallFromCRAN Hmisc 5.2-4
	getAndInstallFromCRAN devtools 2.4.6
	getAndInstallFromCRAN plot3Drgl 1.0.5
	getAndInstallFromCRAN RItools 0.3-5
	getAndInstallFromCRAN plotly 4.11.0
	getAndInstallFromCRAN uplift 0.3.5
elif [ "$R_VERSION" = "4.4.0" ]; then
	getAndInstallFromCRAN abind 1.4-5
	getAndInstallFromCRAN acepack 1.4.2
	getAndInstallFromCRAN AUC 0.3.2
	getAndInstallFromCRAN backports 1.5.0
	getAndInstallFromCRAN base64enc 0.1-3
	getAndInstallFromCRAN bit 4.0.5
	getAndInstallFromCRAN bitops 1.0-7
	getAndInstallFromCRAN boot 1.3-30
	getAndInstallFromCRAN brew 1.0-10
	getAndInstallFromCRAN brio 1.1.5
	getAndInstallFromCRAN cli 3.6.2
	getAndInstallFromCRAN clipr 0.8.0
	getAndInstallFromCRAN cluster 2.1.6
	getAndInstallFromCRAN codetools 0.2-20
	getAndInstallFromCRAN colorspace 2.1-0
	getAndInstallFromCRAN commonmark 1.9.1
	getAndInstallFromCRAN cpp11 0.4.7
	getAndInstallFromCRAN crayon 1.5.2
	getAndInstallFromCRAN curl 5.2.1
	getAndInstallFromCRAN data.table 1.15.4
	getAndInstallFromCRAN deldir 2.0-4
	getAndInstallFromCRAN DEoptimR 1.1-3
	getAndInstallFromCRAN digest 0.6.35
	getAndInstallFromCRAN diptest 0.77-1
	getAndInstallFromCRAN evaluate 0.23
	getAndInstallFromCRAN fansi 1.0.6
	getAndInstallFromCRAN farver 2.1.2
	getAndInstallFromCRAN fastmap 1.2.0
	getAndInstallFromCRAN float 0.3-2
	getAndInstallFromCRAN foreign 0.8-86
	getAndInstallFromCRAN formatR 1.14
	getAndInstallFromCRAN Formula 1.2-5
	getAndInstallFromCRAN fs 1.6.4
	getAndInstallFromCRAN futile.options 1.0.1
	getAndInstallFromCRAN generics 0.1.3
	getAndInstallFromCRAN getopt 1.20.4
	getAndInstallFromCRAN gitcreds 0.1.2
	getAndInstallFromCRAN glue 1.7.0
	getAndInstallFromCRAN gtools 3.9.5
	getAndInstallFromCRAN HDtweedie 1.2
	getAndInstallFromCRAN highlight 0.5.1
	getAndInstallFromCRAN ini 0.3.1
	getAndInstallFromCRAN isoband 0.2.7
	getAndInstallFromCRAN iterators 1.0.14
	getAndInstallFromCRAN jpeg 0.1-10
	getAndInstallFromCRAN jsonlite 1.8.8
	getAndInstallFromCRAN kernlab 0.9-32
	getAndInstallFromCRAN KernSmooth 2.23-24
	getAndInstallFromCRAN labeling 0.4.3
	getAndInstallFromCRAN lattice 0.22-6
	getAndInstallFromCRAN lazyeval 0.2.2
	getAndInstallFromCRAN LiblineaR 2.10-23
	getAndInstallFromCRAN magrittr 2.0.3
	getAndInstallFromCRAN MASS 7.3-60.2
	getAndInstallFromCRAN matrixStats 1.3.0
	getAndInstallFromCRAN mclust 6.1.1
	getAndInstallFromCRAN mime 0.12
	getAndInstallFromCRAN misc3d 0.9-1
	getAndInstallFromCRAN mlbench 2.1-5
	getAndInstallFromCRAN modeltools 0.2-23
	getAndInstallFromCRAN mvtnorm 1.2-5
	getAndInstallFromCRAN nnet 7.3-19
	getAndInstallFromCRAN packrat 0.9.2
	getAndInstallFromCRAN pixmap 0.4-13
	getAndInstallFromCRAN pkgconfig 2.0.3
	getAndInstallFromCRAN png 0.1-8
	getAndInstallFromCRAN praise 1.0.0
	getAndInstallFromCRAN prettyunits 1.2.0
	getAndInstallFromCRAN proxy 0.4-27
	getAndInstallFromCRAN ps 1.7.6
	getAndInstallFromCRAN R.methodsS3 1.8.2
	getAndInstallFromCRAN R6 2.5.1
	getAndInstallFromCRAN randomForest 4.7-1.1
	getAndInstallFromCRAN rappdirs 0.3.3
	getAndInstallFromCRAN RColorBrewer 1.1-3
	getAndInstallFromCRAN Rcpp 1.0.12
	getAndInstallFromCRAN RcppParallel 5.1.7
	getAndInstallFromCRAN remotes 2.5.0
	getAndInstallFromCRAN renv 1.0.7
	getAndInstallFromCRAN RhpcBLASctl 0.23-42
	getAndInstallFromCRAN rlang 1.1.3
	getAndInstallFromCRAN rpart 4.1.23
	getAndInstallFromCRAN rprojroot 2.0.4
	getAndInstallFromCRAN rstudioapi 0.16.0
	getAndInstallFromCRAN RUnit 0.4.33
	getAndInstallFromCRAN shape 1.4.6.1
	getAndInstallFromCRAN slam 0.1-50
	getAndInstallFromCRAN sourcetools 0.1.7-1
	getAndInstallFromCRAN SparseM 1.83
	getAndInstallFromCRAN sparsepp 1.22
	getAndInstallFromCRAN spatial 7.3-17
	getAndInstallFromCRAN statmod 1.5.0
	getAndInstallFromCRAN stringi 1.8.4
	getAndInstallFromCRAN svd 0.5.5
	getAndInstallFromCRAN sys 3.4.2
	getAndInstallFromCRAN tweedie 2.3.5
	getAndInstallFromCRAN utf8 1.2.4
	getAndInstallFromCRAN uuid 1.2-0
	getAndInstallFromCRAN versions 0.3
	getAndInstallFromCRAN viridisLite 0.4.2
	getAndInstallFromCRAN whisker 0.4.1
	getAndInstallFromCRAN withr 3.0.0
	getAndInstallFromCRAN xfun 0.44
	getAndInstallFromCRAN xtable 1.8-4
	getAndInstallFromCRAN yaml 2.3.8
	getAndInstallFromCRAN zip 2.3.1
	getAndInstallFromCRAN checkmate 2.3.1
	getAndInstallFromCRAN PKI 0.1-12
	getAndInstallFromCRAN bit64 4.0.5
	getAndInstallFromCRAN caTools 1.18.2
	getAndInstallFromCRAN RCurl 1.98-1.14
	getAndInstallFromCRAN sessioninfo 1.2.2
	getAndInstallFromCRAN munsell 0.5.1
	getAndInstallFromCRAN diffobj 0.3.5
	getAndInstallFromCRAN robustbase 0.99-2
	getAndInstallFromCRAN lambda.r 1.2.4
	getAndInstallFromCRAN optparse 1.7.5
	getAndInstallFromCRAN foreach 1.5.2
	getAndInstallFromCRAN Matrix 1.7-0
	getAndInstallFromCRAN nlme 3.1-164
	getAndInstallFromCRAN sp 2.1-4
	getAndInstallFromCRAN zoo 1.8-12
	getAndInstallFromCRAN class 7.3-22
	getAndInstallFromCRAN prabclus 2.3-3
	getAndInstallFromCRAN plot3D 1.4.1
	getAndInstallFromCRAN libcoin 1.0-10
	getAndInstallFromCRAN flexmix 2.3-19
	getAndInstallFromCRAN R.oo 1.26.0
	getAndInstallFromCRAN desc 1.4.3
	getAndInstallFromCRAN lgr 0.4.4
	getAndInstallFromCRAN processx 3.8.4
	getAndInstallFromCRAN RcppArmadillo 0.12.8.3.0
	getAndInstallFromCRAN RcppEigen 0.3.4.0.0
	getAndInstallFromCRAN interp 1.1-6
	getAndInstallFromCRAN cachem 1.1.0
	getAndInstallFromCRAN ellipsis 0.3.2
	getAndInstallFromCRAN htmltools 0.5.8.1
	getAndInstallFromCRAN later 1.3.2
	getAndInstallFromCRAN lifecycle 1.0.4
	getAndInstallFromCRAN xml2 1.3.6
	getAndInstallFromCRAN askpass 1.2.0
	getAndInstallFromCRAN highr 0.11
	getAndInstallFromCRAN tinytex 0.51
	getAndInstallFromCRAN gplots 3.1.3.1
	getAndInstallFromCRAN futile.logger 1.4.3
	getAndInstallFromCRAN irlba 2.3.5.1
	getAndInstallFromCRAN MatrixExtra 0.1.15
	getAndInstallFromCRAN mlapi 0.1.1
	getAndInstallFromCRAN survival 3.6-4
	getAndInstallFromCRAN xgboost 1.7.7.1
	getAndInstallFromCRAN mgcv 1.9-1
	getAndInstallFromCRAN ade4 1.7-22
	getAndInstallFromCRAN sandwich 3.1-0
	getAndInstallFromCRAN e1071 1.7-14
	getAndInstallFromCRAN flexclust 1.4-2
	getAndInstallFromCRAN fpc 2.2-12
	getAndInstallFromCRAN R.utils 2.12.3
	getAndInstallFromCRAN callr 3.7.6
	getAndInstallFromCRAN xopen 1.0.1
	getAndInstallFromCRAN latticeExtra 0.6-30
	getAndInstallFromCRAN memoise 2.0.1
	getAndInstallFromCRAN crosstalk 1.2.1
	getAndInstallFromCRAN fontawesome 0.5.2
	getAndInstallFromCRAN jquerylib 0.1.4
	getAndInstallFromCRAN sass 0.4.9
	getAndInstallFromCRAN promises 1.3.0
	getAndInstallFromCRAN gtable 0.3.5
	getAndInstallFromCRAN scales 1.3.0
	getAndInstallFromCRAN systemfonts 1.1.0
	getAndInstallFromCRAN vctrs 0.6.5
	getAndInstallFromCRAN rversions 2.1.2
	getAndInstallFromCRAN urlchecker 1.0.1
	getAndInstallFromCRAN openssl 2.2.0
	getAndInstallFromCRAN knitr 1.47
	getAndInstallFromCRAN ROCR 1.0-11
	getAndInstallFromCRAN rsparse 0.5.1
	getAndInstallFromCRAN gbm 2.1.9
	getAndInstallFromCRAN glmnet 4.1-8
	getAndInstallFromCRAN penalized 0.9-52
	getAndInstallFromCRAN TH.data 1.1-2
	getAndInstallFromCRAN pkgbuild 1.4.4
	getAndInstallFromCRAN webshot 0.5.5
	getAndInstallFromCRAN bslib 0.7.0
	getAndInstallFromCRAN httpuv 1.6.15
	getAndInstallFromCRAN gridExtra 2.3
	getAndInstallFromCRAN textshaping 0.4.0
	getAndInstallFromCRAN downlit 0.4.3
	getAndInstallFromCRAN pillar 1.9.0
	getAndInstallFromCRAN purrr 1.0.2
	getAndInstallFromCRAN stringr 1.5.1
	getAndInstallFromCRAN tidyselect 1.2.1
	getAndInstallFromCRAN credentials 2.0.1
	getAndInstallFromCRAN httr 1.4.7
	getAndInstallFromCRAN httr2 1.0.1
	getAndInstallFromCRAN rsconnect 1.3.0
	getAndInstallFromCRAN tables 0.9.25
	getAndInstallFromCRAN MLmetrics 1.1.3
	getAndInstallFromCRAN text2vec 0.6.4
	getAndInstallFromCRAN multcomp 1.4-25
	getAndInstallFromCRAN pkgload 1.3.4
	getAndInstallFromCRAN rcmdcheck 1.4.0
	getAndInstallFromCRAN rmarkdown 2.27
	getAndInstallFromCRAN shiny 1.8.1.1
	getAndInstallFromCRAN ragg 1.3.2
	getAndInstallFromCRAN repr 1.1.7
	getAndInstallFromCRAN tibble 3.2.1
	getAndInstallFromCRAN gert 2.0.1
	getAndInstallFromCRAN gh 1.4.1
	getAndInstallFromCRAN coin 1.4-3
	getAndInstallFromCRAN roxygen2 7.3.1
	getAndInstallFromCRAN htmlwidgets 1.6.4
	getAndInstallFromCRAN miniUI 0.1.1.1
	getAndInstallFromCRAN shinyjs 2.1.0
	getAndInstallFromCRAN IRdisplay 1.1
	getAndInstallFromCRAN dplyr 1.1.4
	getAndInstallFromCRAN ggplot2 3.5.1
	getAndInstallFromCRAN pkgdown 2.0.9
	getAndInstallFromCRAN rematch2 2.1.2
	getAndInstallFromCRAN usethis 2.2.3
	getAndInstallFromCRAN htmlTable 2.4.2
	getAndInstallFromCRAN profvis 0.3.8
	getAndInstallFromCRAN rgl 1.3.1
	getAndInstallFromCRAN tidyr 1.3.1
	getAndInstallFromCRAN viridis 0.6.5
	getAndInstallFromCRAN waldo 0.5.2
	getAndInstallFromCRAN plot3Drgl 1.0.4
	getAndInstallFromCRAN plotly 4.10.4
	getAndInstallFromCRAN RItools 0.3-3
	getAndInstallFromCRAN Hmisc 5.1-3
	getAndInstallFromCRAN testthat 3.2.1.1
	getAndInstallFromCRAN devtools 2.4.5
	getAndInstallFromCRAN uplift 0.3.5
	getAndInstallFromCRAN DT 0.33
else
	getAndInstallFromCRAN abind 1.4-5
	getAndInstallFromCRAN acepack 1.4.1
	getAndInstallFromCRAN AUC 0.3.0
	getAndInstallFromCRAN backports 1.3.0
	getAndInstallFromCRAN base64enc 0.1-3
	getAndInstallFromCRAN bit 4.0.4
	getAndInstallFromCRAN bitops 1.0-7
	getAndInstallFromCRAN boot 1.3-18
	getAndInstallFromCRAN brew 1.0-6
	getAndInstallFromCRAN brio 1.1.2
	getAndInstallFromCRAN clipr 0.7.1
	getAndInstallFromCRAN cluster 2.0.5
	getAndInstallFromCRAN codetools 0.2-15
	getAndInstallFromCRAN colorspace 2.0-2
	getAndInstallFromCRAN commonmark 1.7
	getAndInstallFromCRAN cpp11 0.4.1
	getAndInstallFromCRAN crayon 1.4.2
	getAndInstallFromCRAN curl 4.3.2
	getAndInstallFromCRAN data.table 1.14.2
	getAndInstallFromCRAN DEoptimR 1.0-9
	getAndInstallFromCRAN digest 0.6.28
	getAndInstallFromCRAN diptest 0.76-0
	getAndInstallFromCRAN evaluate 0.14
	getAndInstallFromCRAN fansi 0.5.0
	getAndInstallFromCRAN farver 2.1.0
	getAndInstallFromCRAN fastmap 1.1.0
	getAndInstallFromCRAN foreign 0.8-67
	getAndInstallFromCRAN formatR 1.11
	getAndInstallFromCRAN Formula 1.2-4
	getAndInstallFromCRAN fs 1.5.0
	getAndInstallFromCRAN futile.options 1.0.1
	getAndInstallFromCRAN generics 0.1.1
	getAndInstallFromCRAN getopt 1.20.3
	getAndInstallFromCRAN gitcreds 0.1.1
	getAndInstallFromCRAN glue 1.5.0
	getAndInstallFromCRAN gtable 0.3.0
	getAndInstallFromCRAN gtools 3.9.2
	getAndInstallFromCRAN HDtweedie 1.1
	getAndInstallFromCRAN highlight 0.5.0
	getAndInstallFromCRAN ini 0.3.1
	getAndInstallFromCRAN isoband 0.2.5
	getAndInstallFromCRAN iterators 1.0.13
	getAndInstallFromCRAN jsonlite 1.7.2
	getAndInstallFromCRAN kernlab 0.9-29
	getAndInstallFromCRAN KernSmooth 2.23-15
	getAndInstallFromCRAN labeling 0.4.2
	getAndInstallFromCRAN lattice 0.20-34
	getAndInstallFromCRAN lazyeval 0.2.2
	getAndInstallFromCRAN LiblineaR 1.94-2
	getAndInstallFromCRAN magrittr 2.0.1
	getAndInstallFromCRAN MASS 7.3-45
	getAndInstallFromCRAN mclust 5.4.8
	getAndInstallFromCRAN mime 0.12
	getAndInstallFromCRAN misc3d 0.9-1
	getAndInstallFromCRAN mlbench 2.1-3
	getAndInstallFromCRAN MLmetrics 1.0.0
	getAndInstallFromCRAN modeltools 0.2-23
	getAndInstallFromCRAN mvtnorm 1.0-0
	getAndInstallFromCRAN nnet 7.3-12
	getAndInstallFromCRAN packrat 0.7.0
	getAndInstallFromCRAN pixmap 0.4-12
	getAndInstallFromCRAN pkgconfig 2.0.3
	getAndInstallFromCRAN praise 1.0.0
	getAndInstallFromCRAN prettyunits 1.1.1
	getAndInstallFromCRAN proxy 0.4-20
	getAndInstallFromCRAN ps 1.6.0
	getAndInstallFromCRAN R.methodsS3 1.8.1
	getAndInstallFromCRAN R6 2.5.1
	getAndInstallFromCRAN randomForest 4.6-14
	getAndInstallFromCRAN rappdirs 0.3.3
	getAndInstallFromCRAN RColorBrewer 1.1-2
	getAndInstallFromCRAN Rcpp 1.0.12
	getAndInstallFromCRAN RcppParallel 5.1.4
	getAndInstallFromCRAN remotes 2.4.1
	getAndInstallFromCRAN rlang 1.0.0
	getAndInstallFromCRAN rpart 4.1-10
	getAndInstallFromCRAN rprojroot 2.0.2
	getAndInstallFromCRAN rstudioapi 0.13
	getAndInstallFromCRAN RUnit 0.4.32
	getAndInstallFromCRAN slam 0.1-40
	getAndInstallFromCRAN sourcetools 0.1.7
	getAndInstallFromCRAN SparseM 1.81
	getAndInstallFromCRAN sparsepp 1.22
	getAndInstallFromCRAN spatial 7.3-11
	getAndInstallFromCRAN statmod 1.4.36
	getAndInstallFromCRAN stringi 1.7.5
	getAndInstallFromCRAN svd 0.5
	getAndInstallFromCRAN sys 3.4
	getAndInstallFromCRAN systemfonts 0.2.3
	getAndInstallFromCRAN tweedie 2.3.5
	getAndInstallFromCRAN utf8 1.2.2
	getAndInstallFromCRAN uuid 1.0-3
	getAndInstallFromCRAN versions 0.3
	getAndInstallFromCRAN viridisLite 0.4.0
	getAndInstallFromCRAN whisker 0.4
	getAndInstallFromCRAN withr 2.4.2
	getAndInstallFromCRAN xfun 0.28
	getAndInstallFromCRAN xml2 1.3.2
	getAndInstallFromCRAN xtable 1.8-4
	getAndInstallFromCRAN yaml 2.2.1
	getAndInstallFromCRAN zip 2.2.0
	getAndInstallFromCRAN checkmate 2.0.0
	getAndInstallFromCRAN bit64 4.0.5
	getAndInstallFromCRAN caTools 1.17.1.4
	getAndInstallFromCRAN RCurl 1.95-4.12
	getAndInstallFromCRAN munsell 0.5.0
	getAndInstallFromCRAN diffobj 0.3.5
	getAndInstallFromCRAN robustbase 0.93-7
	getAndInstallFromCRAN lambda.r 1.2.4
	getAndInstallFromCRAN optparse 1.7.1
	getAndInstallFromCRAN cli 3.1.0
	getAndInstallFromCRAN gridExtra 2.3
	getAndInstallFromCRAN foreach 1.5.1
	getAndInstallFromCRAN Matrix 1.2-8
	getAndInstallFromCRAN nlme 3.1-131
	getAndInstallFromCRAN sp 1.4-5
	getAndInstallFromCRAN class 7.3-14
	getAndInstallFromCRAN prabclus 2.3-2
	getAndInstallFromCRAN plot3D 1.4
	getAndInstallFromCRAN flexmix 2.3-17
	getAndInstallFromCRAN R.oo 1.24.0
	getAndInstallFromCRAN processx 3.5.2
	getAndInstallFromCRAN latticeExtra 0.6-28
	getAndInstallFromCRAN RcppArmadillo 0.10.7.3.0
	getAndInstallFromCRAN cachem 1.0.6
	getAndInstallFromCRAN ellipsis 0.3.2
	getAndInstallFromCRAN htmltools 0.5.2
	getAndInstallFromCRAN later 1.3.0
	getAndInstallFromCRAN lifecycle 1.0.1
	getAndInstallFromCRAN purrr 0.3.4
	getAndInstallFromCRAN desc 1.4.0
	getAndInstallFromCRAN stringr 1.4.0
	getAndInstallFromCRAN askpass 1.1
	getAndInstallFromCRAN highr 0.9
	getAndInstallFromCRAN tinytex 0.35
	getAndInstallFromCRAN rversions 2.1.1
	getAndInstallFromCRAN gplots 3.1.1
	getAndInstallFromCRAN futile.logger 1.4.3
	getAndInstallFromCRAN sessioninfo 1.2.1
	getAndInstallFromCRAN glmnet 2.0-2
	getAndInstallFromCRAN irlba 2.3.3
	getAndInstallFromCRAN survival 2.44-1.1
	getAndInstallFromCRAN xgboost 1.0.0.2
	getAndInstallFromCRAN mgcv 1.8-17
	getAndInstallFromCRAN ade4 1.7-18
	getAndInstallFromCRAN e1071 1.7-9
	getAndInstallFromCRAN flexclust 1.4-0
	getAndInstallFromCRAN fpc 2.2-9
	getAndInstallFromCRAN R.utils 2.11.0
	getAndInstallFromCRAN callr 3.7.0
	getAndInstallFromCRAN xopen 1.0.0
	getAndInstallFromCRAN memoise 2.0.0
	getAndInstallFromCRAN vctrs 0.3.8
	getAndInstallFromCRAN crosstalk 1.2.0
	getAndInstallFromCRAN fontawesome 0.2.2
	getAndInstallFromCRAN htmlwidgets 1.5.4
	getAndInstallFromCRAN jquerylib 0.1.4
	getAndInstallFromCRAN sass 0.4.0
	getAndInstallFromCRAN promises 1.2.0.1
	getAndInstallFromCRAN scales 1.1.1
	getAndInstallFromCRAN pkgload 1.2.3
	getAndInstallFromCRAN openssl 1.4.5
	getAndInstallFromCRAN knitr 1.36
	getAndInstallFromCRAN ROCR 1.0-7
	getAndInstallFromCRAN text2vec 0.5.0
	getAndInstallFromCRAN coin 1.0-0
	getAndInstallFromCRAN gbm 2.1.3
	getAndInstallFromCRAN penalized 0.9-51
	getAndInstallFromCRAN RItools 0.1-17
	getAndInstallFromCRAN pkgbuild 1.2.0
	getAndInstallFromCRAN webshot 0.5.2
	getAndInstallFromCRAN pillar 1.6.4
	getAndInstallFromCRAN tidyselect 1.1.1
	getAndInstallFromCRAN bslib 0.3.1
	getAndInstallFromCRAN httpuv 1.6.3
	getAndInstallFromCRAN credentials 1.3.0
	getAndInstallFromCRAN httr 1.4.2
	getAndInstallFromCRAN rsconnect 0.8.24
	getAndInstallFromCRAN htmlTable 2.3.0
	getAndInstallFromCRAN rmarkdown 2.11
	getAndInstallFromCRAN roxygen2 7.2.2
	getAndInstallFromCRAN tables 0.9.6
	getAndInstallFromCRAN rcmdcheck 1.4.0
	getAndInstallFromCRAN repr 1.1.3
	getAndInstallFromCRAN tibble 3.1.6
	getAndInstallFromCRAN shiny 1.7.1
	getAndInstallFromCRAN gert 1.3.0
	getAndInstallFromCRAN gh 1.3.0
	getAndInstallFromCRAN uplift 0.3.5
	getAndInstallFromCRAN IRdisplay 1.0
	getAndInstallFromCRAN dplyr 1.0.7
	getAndInstallFromCRAN ggplot2 3.3.5
	getAndInstallFromCRAN rematch2 2.1.2
	getAndInstallFromCRAN miniUI 0.1.1.1
	getAndInstallFromCRAN shinyjs 2.0.0
	getAndInstallFromCRAN usethis 2.0.1
	getAndInstallFromCRAN tidyr 1.1.4
	getAndInstallFromCRAN viridis 0.6.2
	getAndInstallFromCRAN pkgdown 1.5.1
	getAndInstallFromCRAN waldo 0.3.1
	getAndInstallFromCRAN manipulateWidget 0.11.1
	getAndInstallFromCRAN plotly 4.10.0
	getAndInstallFromCRAN Hmisc 4.3-0
	getAndInstallFromCRAN testthat 3.1.0
	getAndInstallFromCRAN rgl 0.100.54
	getAndInstallFromCRAN devtools 2.4.2
	getAndInstallFromCRAN plot3Drgl 1.0.2
fi
# dependecies from GitHub
R_REMOTES_UPGRADE=never
/usr/local/R/current/bin/R -e "chooseCRANmirror(graphics=FALSE, ind=1); library(devtools); \
  install_github('Zelazny7/isofor') \
" 2>&1 | tee R.install.7.log
checkRInstallLog R.install.7.log
rm R.install.*.log
