3 # set up the working directory
4 tmp <- tempfile('cran2deb')
9 cleanup <- function(dir) {
10 # remove the working directory
11 unlink(dir,recursive=T)
15 prepare_pkg <- function(dir, pkgname) {
16 # download and extract an R package named pkgname
17 # OR the bundle containing pkgname
19 # based loosely on library/utils/R/packages2.R::install.packages
20 # should do nothing Debian specific
22 # first a little trick; change pkgname if pkgname is contained in a bundle
23 if (!(pkgname %in% rownames(available))) {
24 bundle <- r_bundle_of(pkgname)
26 stop(paste('package',pkgname,'is unavailable'))
30 archive <- download.packages(pkgname, dir, available=available, repos='', type="source")[1,2]
31 if (length(grep('\\.\\.',archive)) || normalizePath(archive) != archive) {
32 stop(paste('funny looking path',archive))
36 if (length(grep('\\.zip$',archive))) {
37 cmd = paste('unzip',shQuote(archive))
38 } else if (length(grep('\\.tar\\.gz$',archive))) {
39 cmd = paste('tar','xzf',shQuote(archive))
41 stop(paste('Type of archive',archive,'is unknown.'))
46 stop(paste('Extraction of archive',archive,'failed.'))
51 pkg$path = sub("_\\.(zip|tar\\.gz)", ""
52 ,gsub(.standard_regexps()$valid_package_version, ""
54 if (!file.info(pkg$path)[,'isdir']) {
55 stop(paste(pkg$path,'is not a directory and should be.'))
57 pkg$description = read.dcf(file.path(pkg$path,'DESCRIPTION'))
58 pkg$repoURL = available[pkgname,'Repository']
59 pkg$version = pkg$description[1,'Version']
60 pkg$is_bundle = 'Bundle' %in% names(pkg$description[1,])
61 # note subtly of short circuit operators (no absorption)
62 if ((!pkg$is_bundle && pkg$description[1,'Package'] != pkg$name) ||
63 ( pkg$is_bundle && pkg$description[1,'Bundle'] != pkg$name)) {
64 stop(paste('package name mismatch'))