[R] local source packages install from within R session - cross-platform

From: Ken Termiso <jerk_alert_at_hotmail.com>
Date: Sat 10 Dec 2005 - 07:18:01 EST

I realize that others have struggled with this issue...i.e. http://tolstoy.newcastle.edu.au/~rking/R/help/05/01/9826.html

i am on os.x 10.4 w/ R2.2, and am (perhaps foolishly) also on this quest...

i would like to be able to install downloaded source (tar.gz'd) files from within an R session, and have it work in a X-platform way..i am often not connected to the internet and have libraries that i would like to be able to install in an automated way..

i've tried several things:

1)
install.packages("hs95av2hs3ug6cdf_6.0.0.tar.gz", repos=NULL, method="source")
Error in gzfile(file, "r") : unable to open connection In addition: Warning message:
cannot open compressed file 'hs95av2hs3ug6cdf_6.0.0.tar.gz/DESCRIPTION'

>traceback()

5: gzfile(file, "r")
4: read.dcf(file.path(curPkg, "DESCRIPTION"), c("Package", "Version"))
3: unpackPkg(pkgs[i], pkgnames[i], lib, installWithVers)
2: .install.macbinary(pkgs = pkgs, lib = lib, contriburl = contriburl,
       method = method, available = available, destdir = destdir,
       installWithVers = installWithVers, dependencies = dependencies)
1: install.packages("hs95av2hs3ug6cdf_6.0.0.tar.gz", repos = NULL,
       method = "source")


2) the code in the above thread doesn't work for me on OS X..

file.pkg <- "hs95av2hs3ug6cdf_6.0.0.tar.gz"
path.pkg <- file.path(getwd(), file.pkg)
pkg_path <- paste("file://", path.pkg, sep = "")
install.packages("hs95av2hs3ug6cdf_6.0.0", contriburl=pkg_path, lib = Sys.getenv("R_LIBS"))

Error in gzfile(file, "r") : unable to open connection In addition: Warning message:
cannot open compressed file
'/Users/ken/Desktop/hs95av2hs3ug6cdf_6.0.0.tar.gz/PACKAGES'

>traceback()

5: gzfile(file, "r")
4: read.dcf(file = tmpf, fields = flds)
3: available.packages(contriburl = contriburl, method = method)
2: .install.macbinary(pkgs = pkgs, lib = lib, contriburl = contriburl,
       method = method, available = available, destdir = destdir,
       installWithVers = installWithVers, dependencies = dependencies)
1: install.packages("hs95av2hs3ug6cdf_6.0.0", contriburl = pkg_path,
       lib = Sys.getenv("R_LIBS"))


*with both of those, things get screwy with gzfile(), but calling it directly on the file is fine..

>gzfile("hs95av2hs3ug6cdf_6.0.0.tar.gz")

                    description                           class              
               mode
"hs95av2hs3ug6cdf_6.0.0.tar.gz"                        "gzfile"              
              "rb6"
                           text                          opened              
           can read
                         "text"                        "closed"              
              "yes"
                      can write
                          "yes"




3) i tinkered with the installLocalPackages() from sciViews library...

"installLocalPackages" <-

function(basedir = "d:/R", url = paste("file:",

        basedir, "/bin/windows/contrib", sep = "")) {

        # Install one or several packages from a local source

        if (.Platform$OS.type != "windows")

                stop("This function is for Windows only! Use install.packages instead.")

        localurl <- (length(grep("^file:", url)) > 0)

        if (!localurl)

        stop("installLocalPackages can only install local packages. Use install.packages to install accross the internet")

        a <- CRAN.packages(contriburl = url)

        pkgs <- select.list(a[, 1], , TRUE)

        if (length(pkgs) == 0 || pkgs[1] == "") # The user cancelled the list

                return(invisible(NULL))

        lib <- .libPaths()[1]

    # Install those selected packages

    install.packages(pkgs, lib, CRAN = NULL)

        invisible()

}

this was my final version before i quit -

"installLocalPackages" <-

function(url = paste("file:/",

        basedir, sep = ""), basedir = file.path(getwd()), localPkg) {

        # Install one or several packages from a local source

        localurl <- (length(grep("^file:", url)) > 0)

        if (!localurl)

        stop("installLocalPackages can only install local packages. Use install.packages to install accross the internet")

# a <- available.packages(contriburl = url)

# pkgs <- select.list(a[, 1], , TRUE)

# if (length(pkgs) == 0 || pkgs[1] == "") # The user cancelled the list

# return(invisible(NULL))

        lib <- .libPaths()[1]

    # Install those selected packages

    install.packages(localPkg, lib, CRAN = NULL)

        invisible()

}

ideally, i would like to have installLocalPackages() work in a X-platform way with NO gui; i would like it to accept either a single .tar.gz or several at a time...

any help would be much appreciated - i'm out of ideas...



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Dec 10 07:31:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:35 EST