if (!require(pkg)){
install.packages(pkg)
}
if ("somepackage" %in% row.names(installed.packages()) == FALSE)
install.packages("somepackage")
if (!require(pkg)){
install.packages(pkg)
}
if ("somepackage" %in% row.names(installed.packages()) == FALSE)
install.packages("somepackage")