downloadDependentPackages <- function()

in R/R/sqlPackage.R [1277:1334]


downloadDependentPackages <- function(pkgs, destdir, binaryPackages, sourcePackages, serverVersion,
                                        verbose = getOption("verbose"), pkgType = getOption("pkgType"))
{
    downloadedPkgs <- NULL
    numPkgs <- nrow(pkgs)

    for (pkgIndex in 1:numPkgs)
    {
        pkg = pkgs[pkgIndex,]

        if (verbose)
        {
            write(sprintf("%s  Downloading package [%d/%d] %s (%s)...", pkgTime(), pkgIndex, numPkgs, pkg$Package, pkg$Version), stdout())
        }

        # try first binary package
        #
        downloadedPkg <- utils::download.packages(pkg$Package, destdir = destdir,
                                                  available = binaryPackages, type = pkgType, quiet = TRUE)

        if (length(downloadedPkg) < 1)
        {
            write(sprintf("%s  Could not find binary version in repo, trying source instead...", pkgTime()), stdout())

            # try source package if binary package isn't there
            #
            if(serverVersion$sysname == Sys.info()[['sysname']])
            {
                # If the server and client are the same type,
                # with source packages, we may need to build the binary on the client
                #
                downloadedPkg = buildSourcePackage(pkg$Package, destdir, sourcePackages)
            }
            else
            {
                # If the server and client are NOT the same type,
                # we just download the source package and send it to the server to build
                #
                downloadedPkg <- utils::download.packages(pkg$Package, destdir = destdir,
                                                          available = sourcePackages, type = pkgType, quiet = TRUE)
            }
        }

        if (length(downloadedPkg) < 1)
        {
            stop(sprintf("Failed to download package %s.", pkg$Package), call. = FALSE)
        }

        downloadedPkg[1,2] <- normalizePath(downloadedPkg[1,2], mustWork = FALSE)
        downloadedPkgs <- rbind(downloadedPkgs, downloadedPkg)
    }

    downloadedPkgs <- data.frame(downloadedPkgs, stringsAsFactors = FALSE)
    colnames(downloadedPkgs) <- c("Package", "File")
    rownames(downloadedPkgs) <- downloadedPkgs$Package

    return (downloadedPkgs)
}