PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 17, 2022

[FIXED] How to save verbose output

 August 17, 2022     output, r, verbose     No comments   

Issue

I would like to save the the verbose output of whatever R function to either a variable or file.

In other words, the verbose console output of whatever_R_function(abc, verbose=TRUE) should be saved somewhere.

I tried to play with verbose.output <- capture.output(whatever_R_function(abc, verbose = TRUE)) but it doesn't work as capture.output() captures the non-verbose part of the output only.

Two examples:

install.packages('devtools', verbose=TRUE)

or

library(emayili)
smtp <- server(host = '...',
               port = ...,
               username = '...',
               password = '...')
email <- envelope() %>%
    from('...') %>%
    to('...') %>%
    bcc('...') %>%
    reply('...') %>%
    subject('...') %>%
    html('...') %>%
    attachment('...')
smtp(email, verbose = TRUE)

Thank you.

R 4.0.2 - RStudio 1.3.1093 - macOS 10.15.7


Solution

I didn't dig in to the install.packages code, but smtp appears to use cat directed to stderr() when verbose = TRUE.

The ?capture.output help page says:

Messages sent to stderr() (including those from message, warning and stop) are captured by type = "message". Note that this can be “unsafe” and should only be used with care.

So, I believe if you use capture.output(..., type = "message"), you should get it. There's a strong possibility that this will work for install.packages too.

I'm not sure why this is considered unsafe or what care you should take with it...



Answered By - Gregor Thomas
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing