From b11635695f5989a6d1ddb012b5d31c9550a4b446 Mon Sep 17 00:00:00 2001 From: Arne Johannes Holmin Date: Sat, 28 Oct 2023 15:34:02 +0200 Subject: [PATCH] New argument OSflavour to insertPackage(). (#142) * Added the argument OSflavour in insertPackage() and getPackageInfo(). * Updated ChangeLog and description, and set default value of OSflavour to character(). --- ChangeLog | 4 ++++ R/insertPackage.R | 24 +++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index f409c3ed..c5487b2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2023-10-28 Arne Johannes Holmin + + * R/insertPackage.R: Added the the optional argument OSflavour + 2023-10-09 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Release 0.2.4 diff --git a/R/insertPackage.R b/R/insertPackage.R index 6855c6bb..cb70a548 100644 --- a/R/insertPackage.R +++ b/R/insertPackage.R @@ -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{ @@ -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) @@ -120,7 +127,7 @@ insertPackage <- function(file, "example is 'empty'.") } - pkginfo <- getPackageInfo(file) + pkginfo <- getPackageInfo(file, OSflavour = OSflavour) pkgtype <- identifyPackageType(file, pkginfo) pkgdir <- normalizePath(contrib.url2(repodir, pkgtype, pkginfo["Rmajor"]), mustWork = FALSE) @@ -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() @@ -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"])