On Tue, Dec 4, 2012 at 2:12 PM, David Romano <dromano@stanford.edu> wrote:

>
>
> On Tue, Dec 4, 2012 at 10:22 AM, Duncan Murdoch <murdoch.duncan@gmail.com>wrote:
>
>> On 04/12/2012 12:54 PM, David Romano wrote:
>>
>>> Hi everyone,
>>>
>>> I normally include a call to browser() as I'm working out the kinks in my
>>> scripts, and I am always able to step through each line by hitting
>>> "Return", but for some reason, in the scripts I'm working on now, hitting
>>> "Return" seems to cause execution of *all* the lines in my script.  I've
>>> restarted R several times in case it was stuck in a bad state for some
>>> reason, but I'm consistently getting this behavior anyway.  Has anyone
>>> run
>>> into this problem before?  Maybe I inadvertently reset preferences?
>>>
>>
>> I wouldn't have expected that to work.  Calling browser() from within a
>> function will let you step through the function, but calling it from within
>> a script doesn't.  Do you really have some scripts where this worked?
>>
>> Duncan Murdoch
>>
>>
>
> Hi Duncan (and this addresses Michael's earlier comment, too),
>
> I've been using browser() in scripts since this summer, which is when I
> started using R, and -- until now -- it has always worked to step through
> the scripts, and -- in regards to Michael's comment -- whether or not there
> were blank lines in the script...
>
> David Romano
>
>
Hi everyone,

I forgot to cc r-help in the response above, and found out why browser()
had been working in my scripts up to now:  All of my scripts so far had
consisted of a body of code that was applied in the same range of contexts
via nested 'for' loops, so that each script had the form

browser()
for (c in context){
  body
}

in which case I could run through the body one line at a time.

So -- outside of when it's called from inside a function -- I still can't
make sense of exactly when browser() will do this, but I now have at least
one way to run through a script.

Thanks to Michael and Duncan for their skepticism, which kept me going in
search of what happened!

David Romano







>
>
>>
>>> An example which produces this behavior is the following:
>>>
>>> file bugcheck.r:
>>>
>>> browser()
>>>
>>> a <- 1
>>> b <- 2
>>>
>>> > source("bugcheck.r")
>>> Called from: eval(expr, envir, enclos)
>>> Browse[1]>  <Return>
>>> >
>>> > ls()
>>> [1] "a" "b"
>>> > a
>>> [1] 1
>>> > b
>>> [1] 2
>>>
>>> I'd be grateful for any help in resolving this!
>>>
>>> Thanks,
>>> David Romano
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________**________________
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>

	[[alternative HTML version deleted]]


