From c501d00896283d3fa482e4d10e77b93d7734bd79 Mon Sep 17 00:00:00 2001 From: maechler Date: Thu, 5 Sep 2024 12:36:02 +0000 Subject: [PATCH] cosmetics for debugging git-svn-id: https://svn.r-project.org/R/trunk@87098 00db46b3-68df-0310-9c12-caf00c1e9a41 --- src/library/utils/R/Sweave.R | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/library/utils/R/Sweave.R b/src/library/utils/R/Sweave.R index 2abb9122a43..71c90417186 100644 --- a/src/library/utils/R/Sweave.R +++ b/src/library/utils/R/Sweave.R @@ -1,7 +1,7 @@ # File src/library/utils/R/Sweave.R # Part of the R package, https://www.R-project.org # -# Copyright (C) 1995-2023 The R Core Team +# Copyright (C) 1995-2024 The R Core Team # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -181,7 +181,7 @@ Sweave <- function(file, driver = RweaveLatex(), on.exit() # clear action to finish with error = TRUE drobj$srcFilenames <- srcFilenames driver$finish(drobj) -} +} ## end{ Sweave } SweaveReadFile <- function(file, syntax, encoding = "") { @@ -285,8 +285,7 @@ SweaveReadFile <- function(file, syntax, encoding = "") attr(text, "srcLinenum") <- srcLinenum attr(text, "srcFilenum") <- srcFilenum text -} - +} ## end{ SweaveReadFile } ###********************************************************** @@ -416,14 +415,17 @@ SweaveHooks <- function(options, run = FALSE, envir = .GlobalEnv) } ### For R CMD xxxx ------------------------------------------ -.Sweave <- function(args = NULL, no.q = interactive()) +.Sweave <- function(args = NULL, no.q = interactive(), + verbose = no.q || nzchar(Sys.getenv("R_DEBUG_dotSweave"))) { - options(warn = 1) + op <- options(warn = 1) + if(no.q) on.exit(options(op)) if (is.null(args)) { args <- commandArgs(TRUE) args <- paste(args, collapse=" ") args <- strsplit(args,'nextArg', fixed = TRUE)[[1L]][-1L] } + if(verbose) { cat(".Sweave args:\n"); str(args) } Usage <- function() { cat("Usage: R CMD Sweave [options] file", @@ -515,6 +517,7 @@ SweaveHooks <- function(options, run = FALSE, envir = .GlobalEnv) Usage() do_exit(1L) } + ## arguments for buildVignette(): args <- list(file=file, tangle=FALSE, latex=toPDF, engine=engine, clean=clean) if(nzchar(driver)) args <- c(args, driver = driver) args <- c(args, encoding = encoding) @@ -522,13 +525,13 @@ SweaveHooks <- function(options, run = FALSE, envir = .GlobalEnv) opts <- eval(str2expression(paste0("list(", options, ")"))) args <- c(args, opts) } + if(verbose) { cat("Calling tools::buildVignette() with args\n"); str(args) } output <- do.call(tools::buildVignette, args) message("Output file: ", output) if (toPDF && compact != "no" && length(output) == 1 && grepl(".pdf$", output, ignore.case=TRUE)) { ## - ## Same code as used for --compact-vignettes in - ## .build_packages() ... + ## Same code as used for --compact-vignettes in .build_packages() message("Compacting PDF document") if(compact %in% c("gs", "gs+qpdf", "both")) { gs_cmd <- tools::find_gs_cmd(Sys.getenv("R_GSCMD", "")) @@ -548,11 +551,12 @@ SweaveHooks <- function(options, run = FALSE, envir = .GlobalEnv) message(paste(format(res), collapse = "\n")) } do_exit() -} +} # end {.Sweave} .Stangle <- function(args = NULL, no.q = interactive()) { - options(warn = 1) + op <- options(warn = 1) + if(no.q) on.exit(options(op)) if (is.null(args)) { args <- commandArgs(TRUE) args <- paste(args, collapse=" ")