Quiet parameter for Maaslin2()

The options for the Maaslin2():

Maaslin2(
    input_data,
    input_metadata,
    output,
    min_abundance = 0.0,
    min_prevalence = 0.1,
    min_variance = 0.0,
    normalization = "TSS",
    transform = "LOG",
    analysis_method = "LM",
    max_significance = 0.25,
    random_effects = NULL,
    fixed_effects = NULL,
    correction = "BH",
    standardize = TRUE,
    cores = 1,
    plot_heatmap = TRUE,
    plot_scatter = TRUE,
    heatmap_first_n = 50,
    reference = NULL
)

I’m using version 1.12.0.

It would be helpful to include a quiet parameter, given that the standard output of the function can be quite large and thus takes up a lot of space in an Rmarkdown or Quarto notebook.

I believe you can handle this by setting the appropriate log level with the logging package that Maaslin2 uses internally (tutorial here: http://logging.r-forge.r-project.org/sample_session.php) .

Failing that, you can try setting the appropriate code chunk option. IIRC what you want here is message = FALSE. Code Chunks

I believe you can handle this by setting the appropriate log level with the logging package that Maaslin2 uses internally

Thanks @andrewGhazi for the suggestion! It would be great to have that info included in the Maaslin2() function docs.

Failing that, you can try setting the appropriate code chunk option. IIRC what you want here is message = FALSE

The downside of message = FALSE is that it eliminates all messages instead of just reducing the verbosity.

Also, message = FALSE only works for knitting, and not for just interactive running of code chunks.

@andrewGhazi Even if I set logging::setLevel("ERROR"), the entire Maaslin2() output is written to the console.

The Maaslin2() code sets the logging level within the function:

        logging::basicConfig(level = 'FINEST')
        logging::addHandler(logging::writeToFile, 
            file = log_file, level = "DEBUG")
        logging::setLevel(20, logging::getHandler('basic.stdout'))

…so even if I change the log level prior to running the function, the log level will be overridden by the function code.

It appears that the log level needs to be provided as a parameter in the function, and not hard-coded.

Ah good catch. We’re internally discussing the best way to change this while preserving the existing expected behavior, but in the meantime for your purposes you could just do something like 1) clone the repo 2) remove those lines 3) devtools::install()

Modifying the codebase limits reproducibility, so I’ll just go with the verbose output for now

Hi all!

Here is a potential workaround:

# place all output to temporary file
sink(file.path(tempdir(), "maaslin2_output.txt"), append = TRUE)
# run Maaslin2
fit <- Maaslin2::Maaslin2(
    input_data = input_data,
    input_metadata = input_metadata,
    output = output,
    fixed_effects = fixed_effects
)
# close connection to temporary file
sink()
# check output is there
readLines(file.path(tempdir(), "maaslin2_output.txt"))

Thanks :slight_smile:

1 Like