[R] Trapping option settings

David A Vavra davavra at verizon.net
Wed Jul 18 22:00:04 CEST 2012


Jim,

Thanks. 

It wasn't sure if merely overriding the options function by placing one in
the global environment would guarantee it would be the one actually called.
In any case, I didn't know how to identify the caller. This is quite helpful
and looks promising. I'll give it a try.

DAV




-----Original Message-----
From: jim holtman [mailto:jholtman at gmail.com] 
Sent: Monday, July 16, 2012 9:59 PM
To: David A Vavra
Cc: r-help at r-project.org
Subject: Re: [R] Trapping option settings

Here is one way by redefining 'options' so you can check for 'width'
and then call the 'options' in 'base':


> options <-  # define 'options' in Global
+ function(...)
+ {
+     args <- list(...)  # get arguments
+     if ('width' %in% names(args)){  # see if 'width' is in them
+         .caller <- sys.calls()  # get where called from
+         if (length(.caller) == 1)  # called from command line
+             .caller <- "Rgui"
+         else .caller <- as.character(.caller[[length(.caller) - 1]])[1]
+         cat("width being changed:", args[['width']], "Called from",
.caller, '\n')
+     }
+     base::options(...)  # call the real options
+ }
>
>
> options(width = 123) # test at command line
width being changed: 123 Called from Rgui
> f.myfunc <- function() options(width = 456)  # within a function
> f.myfunc()
width being changed: 456 Called from f.myfunc
>




On Mon, Jul 16, 2012 at 9:01 PM, David A Vavra <davavra at verizon.net> wrote:
> Something has been changing the setting the width option to 10000 and not
> resetting it. It does this intermittently. What I would like to do is trap
> changing the setting so I can determine where the change is occurring and
> hopefully fix it.
>
> Is there any easy way to do this?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list