1

The code runs fine and the PDF comes out nicely, but I am constantly getting a warning message printed to the PDF. I have tried everything: warning = FALSE, message = FALSE, suppressWarnings(), options(warn = -1), all of it. Before I even run the MK test, I remove subsets with less than 4 observations and then I also apply suppressWarnings() to the test, but I can't get the warning message to stop printing.

Code chunk settings as follows:

{r, echo=FALSE, warning = FALSE, message = FALSE, results = 'asis', fig.align= "center", fig.width = 7, fig.height = 5}

Lots of other code in between...then:

TSP_well_analyte = split(analytical_subset$ValidationResult_, analytical_subset$Analyte) #Creates groups of data based on analyte for MK analysis

TSP_well_analyte_short = TSP_well_analyte[lengths(TSP_well_analyte)>=4] #Remove less than 4 for MK analysis

mk_results = suppressWarnings(lapply(TSP_well_analyte_short, function(y) unlist(MannKendall(y)))) #Applies MK analysis by groups, stores all MK stats

mk_df = as.data.frame(mk_results) #Saves as a data frame for calling in stats

PDF runs fine but prints the following warning, which I have to then go in and delete manually with Adobe Acrobat:

WARNING: Error exit, tauk2. IFAULT = 12

My goal is to make this script fully automated (no manual editing to PDF), so any insight would be most appreciated; I've been driving myself crazy over it.

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • According to https://gis.stackexchange.com/questions/299098/mann-kendall-test-with-r the function doesn't use warning() or a message() to print that warning, it uses `cat`, so perhaps you can wrap it with `invisible()` ? E.g. https://stackoverflow.com/a/48503375/12957340 – jared_mamrot Feb 04 '21 at 03:52
  • 2
    That's not an R warning (should have been `Warning:`, not all-caps), the package is [using `cat`](https://github.com/cran/Kendall/blob/3001da25f1bbfb31b07f054cc55f39e2aa7fee97/R/Kendall.R#L38). Use `invisible(capture.output(...))`. – r2evans Feb 04 '21 at 03:52
  • 1
    For example, see `ret <- lapply(1:3, function(z) {cat("quux\n");z+1;})` and then `invisible(capture.output(ret <- lapply(1:3, function(z) {cat("quux\n");z+1;})))`. – r2evans Feb 04 '21 at 03:54
  • 1
    `invisible(capture.output(mk_results <- lapply(TSP_well_analyte_short, function(y) unlist(MannKendall(y)))))` – r2evans Feb 04 '21 at 03:55

0 Answers0