I would point you at last.warning, but also note that it says this in
?warnings:

Warning:

     It is undocumented where 'last.warning' is stored nor that it is
     visible, and this is subject to change.


But it does seem like you could test if your warning was already in there, eg


mywarningstring %in% names(last.warnings)



On Fri, Oct 21, 2016 at 12:39 AM, Pavel N. Krivitsky <pa...@uow.edu.au>
wrote:

> Dear All,
>
> I have a package (ergm, in case you are wondering) that has some low-
> level routines (say, low()) that produce messages that the end-user
> needs to see and that tend to be called multiple times for every time
> the top-level routine (say, high()) is called, often by other routines
> that are top-level routines themselves.
>
> What I'd like to do to have the low-level routine print the message the
> first time it's called for a given top-level call, and then "remember"
> and stay silent the next time to avoid spamming the end-user.
>
> In other words,
>    1. high()
>       1. low()
>          1. print message
>       2. low()
>          1. don't print message
>       3. high()
>          1. low()
>             1. don't print message
>    2. high()
>       1. low()
>          1. print message
>
> One way to do that that I can see is to use local() to create a
> blacklist of messages that have already been printed, which get cleared
> every time the top-level call exists. I.e.,
>    1. Use local() with a list of messages printed so far and a status of
>       "active" or "inactive" (the initial state), which returns  a
>       function that can query and update both of those.
>    2. When high() is called, it first checks if the blacklist is active.
>       1. If it's active, then this high() must have been called from
>          another high(), so it leaves the blacklist alone.
>       2. If it's inactive, then it must be the top-level call, so it sets
>          it to active and sets an on.exit() handler to clear the blacklist
>          and set it to inactive.
>    3. When low() wants to print a message, it queries the blacklist to see
>       if it's already printed it. If not, it prints and adds it to the
>       list.
>    4. When the top-level high() finishes, the blacklist is cleared and set
>       to inactive.
>
> However, I wonder if there already is a way to do that, ideally built
> in.
>
>                                         Any thoughts?
>                                         Pavel
>
>
>
> --
> Pavel Krivitsky
> Lecturer in Statistics
> National Institute of Applied Statistics Research Australia (NIASRA)
> School of Mathematics and Applied Statistics | Building 39C Room 154
> University of Wollongong NSW 2522 Australia
> T +61 2 4221 3713
> Web (NIASRA): http://niasra.uow.edu.au/index.html
> Web (Personal): http://www.krivitsky.net/research
> ORCID: 0000-0002-9101-3362
>
> NOTICE: This email is intended for the addressee named and may contain
> confidential information. If you are not the intended recipient, please
> delete it and notify the sender. Please consider the environment before
> printing this email.
>
> ______________________________________________
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

        [[alternative HTML version deleted]]

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to