Re: [R] setting options only inside functions

2011-05-02 Thread luke-tierney
Subject: Re: [R] setting options only inside functions The Python solution does not extend, at least not cleanly, to things like dev on/ dev off or to Hadley's locale example. In any case if I am reading the Python source correctly on how they handle user interrupts this solution has the same non

Re: [R] setting options only inside functions

2011-04-29 Thread luke-tierney
The Python solution does not extend, at least not cleanly, to things like dev on/ dev off or to Hadley's locale example. In any case if I am reading the Python source correctly on how they handle user interrupts this solution has the same non-robusness to user interrupts issue that Bill's

Re: [R] setting options only inside functions

2011-04-29 Thread Jonathan Daily
In python, opening a connection using with allows for a temporary assignment using as. So: with file(/path/to/file) as con: permanent_object = function(con) would provide the return of function(con) globally, but close con. If function(con) causes an error, con is still closed. I agree with

Re: [R] setting options only inside functions

2011-04-29 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of luke-tier...@uiowa.edu Sent: Friday, April 29, 2011 9:35 AM To: Jonathan Daily Cc: r-help@r-project.org; Hadley Wickham; Barry Rowlingson Subject: Re: [R] setting options only

Re: [R] setting options only inside functions

2011-04-28 Thread Jonathan Daily
I would also love to see this implemented in R, as my current solution to the issue of doing tons of open/close, dev/dev.off, etc. is to use snippets in my IDE, and in the end I feel like it is a hack job. A pythonic with function would also solve most of the situations where I have had to use

[R] setting options only inside functions

2011-04-27 Thread Jannis
Dear list members, is it possible to set some options only inside a function so that the original options are restored once the function is finished or aborted due to an error? Until now I do something like: dummy=function() { old.options=options(error=dummy1())

Re: [R] setting options only inside functions

2011-04-27 Thread Jeremy Hetzel
See ?on.exit Jeremy On Wednesday, April 27, 2011 9:16:13 AM UTC-4, Jannis wrote: Dear list members, is it possible to set some options only inside a function so that the original options are restored once the function is finished or aborted due to an error? Until now I do something

Re: [R] setting options only inside functions

2011-04-27 Thread Uwe Ligges
On 27.04.2011 15:16, Jannis wrote: Dear list members, is it possible to set some options only inside a function so that the original options are restored once the function is finished or aborted due to an error? Until now I do something like: dummy=function() {

Re: [R] setting options only inside functions

2011-04-27 Thread Jonathan Daily
There is probably a more elegant way to do this, but you could write it into dummy1(): dummy1 - function() { ...original function options(old.options) } Alternatively, you could use ?tryCatch with the finally argument as a call to options. HTH, Jon On Wed, Apr 27, 2011 at 9:16 AM, Jannis

Re: [R] setting options only inside functions

2011-04-27 Thread Jannis
, 27.4.2011: Von: Jonathan Daily biomathjda...@gmail.com Betreff: Re: [R] setting options only inside functions An: Jannis bt_jan...@yahoo.de CC: r-help@r-project.org Datum: Mittwoch, 27. April, 2011 13:35 Uhr There is probably a more elegant way to do this, but you could write

Re: [R] setting options only inside functions

2011-04-27 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jannis Sent: Wednesday, April 27, 2011 11:16 AM To: Jonathan Daily Cc: r-help@r-project.org Subject: Re: [R] setting options only inside functions Thanks to all who supplied

Re: [R] setting options only inside functions

2011-04-27 Thread Hadley Wickham
This has the side effect of ignoring errors and even hiding the error messages.  If you are concerned about multiple calls to on.exit() in one function you could define a new function like  withOptions - function(optionList, expr) {   oldOpts - options(optionList)  

Re: [R] setting options only inside functions

2011-04-27 Thread luke-tierney
Put together a list and we can see what might make sense. If we did take this on it would be good to think about providing a reasonable mechanism for addressing the small flaw in this function as it is defined here. Best, luke On Wed, 27 Apr 2011, Hadley Wickham wrote: This has the side

Re: [R] setting options only inside functions

2011-04-27 Thread Hadley Wickham
Put together a list and we can see what might make sense.  If we did take this on it would be good to think about providing a reasonable mechanism for addressing the small flaw in this function as it is defined here. In devtools, I have: #' Evaluate code in specified locale. with_locale -

Re: [R] setting options only inside functions

2011-04-27 Thread William Dunlap
From: h.wick...@gmail.com [mailto:h.wick...@gmail.com] On Behalf Of Hadley Wickham Sent: Wednesday, April 27, 2011 2:21 PM To: luke-tier...@uiowa.edu Cc: William Dunlap; r-help@r-project.org Subject: Re: [R] setting options only inside functions Put together a list and we can see what

Re: [R] setting options only inside functions

2011-04-27 Thread Barry Rowlingson
but it's a little clumsy, because with_connection(file(myfile.txt), {do stuff...}) isn't very useful because you have no way to reference the connection that you're using. Ruby's blocks have arguments which would require big changes to R's syntax.  One option would to use pronouns: