Skip to content

Commit

Permalink
Sync .package_apply() with .unpacked_source_repository_apply().
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@84935 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
hornik committed Aug 11, 2023
1 parent 4b57e58 commit 4591d96
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/library/tools/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ function()
### ** .package_apply

.package_apply <-
function(packages = NULL, FUN, ...,
function(packages = NULL, FUN, ..., pattern = "*", verbose = TRUE,
Ncpus = getOption("Ncpus", 1L))
{
## Apply FUN and extra '...' args to all given packages.
Expand All @@ -1974,12 +1974,20 @@ function(packages = NULL, FUN, ...,
packages <-
unique(utils::installed.packages(priority = "high")[ , 1L])

one <- function(p)
tryCatch(FUN(p, ...),
error = function(e)
noquote(paste("Error:",
conditionMessage(e))))
## (Just don't throw the error ...)
## For consistency with .unpacked_source_repository_apply(), take
## 'pattern' as a wildcard pattern.
if(pattern != "*")
packages <- packages[grepl(utils::glob2rx(pattern), packages)]

## Keep in sync with .unpacked_source_repository_apply().
## <FIXME>
## Should we really catch errors?
one <- function(p) {
if(verbose)
message(sprintf("processing %s", p))
tryCatch(FUN(p, ...), error = identity)
}
## </FIXME>

## Would be good to have a common wrapper ...
if(Ncpus > 1L) {
Expand Down Expand Up @@ -2425,11 +2433,15 @@ function(dir, FUN, ..., pattern = "*", verbose = FALSE,
dfiles <- Sys.glob(file.path(dir, pattern, "DESCRIPTION"))
paths <- dirname(dfiles)

## Keep in sync with .package_apply().
## <FIXME>
## Should we really catch errors?
one <- function(p) {
if(verbose)
message(sprintf("processing %s", basename(p)))
FUN(p, ...)
tryCatch(FUN(p, ...), error = identity)
}
## </FIXME>

## Would be good to have a common wrapper ...
if(Ncpus > 1L) {
Expand Down

0 comments on commit 4591d96

Please sign in to comment.