Skip to content

Commit

Permalink
New argument OSflavour to insertPackage(). (#142)
Browse files Browse the repository at this point in the history
* Added the argument OSflavour in insertPackage() and getPackageInfo().

* Updated ChangeLog and description, and set default value of OSflavour to character().
  • Loading branch information
arnejohannesholmin authored Oct 28, 2023
1 parent a905da6 commit b116356
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2023-10-28 Arne Johannes Holmin <arnejh@hi.no>

* R/insertPackage.R: Added the the optional argument OSflavour

2023-10-09 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Release 0.2.4
Expand Down
24 changes: 21 additions & 3 deletions R/insertPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
##' either \dQuote{gh-pages} indicating a branch of that name, or
##' \dQuote{docs/} directory in the main branch. The default value can
##' be overridden via the \dQuote{dratBranch} option.
##' @param OSflavour an optional string naming the OSflavour, which is otherwise read as
##' the second element of the 'Built' field of the \code{file}. For packages that do not
##' need compilation on macOS for R >= 4.3 the 'Built' field is empty in the DESCRIPTION
##' in a binary file (tgz), in which case it can be useful to set the \code{OSflavour}
##' e.g. by the value of R.Version()$platform, so that \code{\link{insertPackages}} inserts
##' the binary into the appropriate sub folder (under bin/maxosx).
##' @return NULL is returned.
##' @examples
##' \dontrun{
Expand All @@ -72,6 +78,7 @@ insertPackage <- function(file,
pullfirst = FALSE,
action = c("none", "archive", "prune"),
location = getOption("dratBranch", "gh-pages"),
OSflavour = character(),
...) {

if (!file.exists(file)) stop("File ", file, " not found\n", call. = FALSE)
Expand Down Expand Up @@ -120,7 +127,7 @@ insertPackage <- function(file,
"example is '<!doctype html><title>empty</title>'.")
}

pkginfo <- getPackageInfo(file)
pkginfo <- getPackageInfo(file, OSflavour = OSflavour)
pkgtype <- identifyPackageType(file, pkginfo)
pkgdir <- normalizePath(contrib.url2(repodir, pkgtype, pkginfo["Rmajor"]),
mustWork = FALSE)
Expand Down Expand Up @@ -272,12 +279,18 @@ identifyPackageType <- function(file, pkginfo = getPackageInfo(file)) {
##'
##' @title Get information from a binary package
##' @param file the fully qualified path of the package
##' @section Note:
##' @param OSflavour an optional string naming the OSflavour, which is otherwise read as
##' the second element of the 'Built' field of the \code{file}. For packages that do not
##' need compilation on macOS for R >= 4.3 the 'Built' field is empty in the DESCRIPTION
##' in a binary file (tgz), in which case it can be useful to set the \code{OSflavour}
##' e.g. by the value of R.Version()$platform, so that \code{\link{insertPackages}} inserts
##' the binary into the appropriate sub folder (under bin/maxosx).
##' ##' @section Note:
##' This is an internal function, use \code{:::} to access it from outside
##' the internal package code.
##' @return A named vector with several components
##' @author Dirk Eddelbuettel
getPackageInfo <- function(file) {
getPackageInfo <- function(file, OSflavour = character()) {
if (!file.exists(file)) stop("File ", file, " not found!", call. = FALSE)

td <- tempdir()
Expand Down Expand Up @@ -305,6 +318,11 @@ getPackageInfo <- function(file) {

fields <- strsplit(builtstring, "; ")[[1]]
names(fields) <- c("Rversion", "OSflavour", "Date", "OS")

# Insert the OSflavour if specified by the user:
if(length(OSflavour) && is.character(OSflavour)) {
fields[["OSflavour"]] <- OSflavour
}

rmajor <- gsub("^R (\\d\\.\\d)\\.\\d.*", "\\1", fields["Rversion"])

Expand Down

0 comments on commit b116356

Please sign in to comment.