Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Martin Maechler
> Peter Bosa 
> on Tue, 22 Aug 2017 14:39:50 + writes:

> Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).
> When running a repeat function, the break command causes an error message 
if the repeat command refers to code within a file, but does not produce an 
error if the code is contained within the repeat{} command.

  > Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).
  > 
  > When running a repeat function, the break command causes an error message 
if the repeat command refers to code within a file, but does not produce an 
error if the code is contained within the repeat{} command.
  > 
  > For example, the following code runs fine:
  > 
  > x <- 1
  > y <- 5
  > 
  > repeat {
  >   if(x < y) {
  > print("No Break Dance :-(")
  > x = x + 1
  >   } else {
  > print("Break Dance!")
  > break
  >   }
  > }
  > 
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "Break Dance!"
  > >
  > 
  > However, if I take the loop contents of the repeat{} function, and save 
them to a file (breakTest.R) that contains the following:
  > 
  > if(x < y) {
  >   print("No Break Dance :-(")
  >   x = x + 1
  > } else {
  >   print("Break Dance!")
  >   break
  > }
  > 
  > And then run the following code:
  > 
  > x <- 1
  > y <- 5
  > 
  > repeat{
  >   source("./breakTest.R")
  > }
  > 
  > I get the following error:
  > 
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "No Break Dance :("
  > [1] "Break Dance!"
  > Error in eval(ei, envir) : no loop for break/next, jumping to top level
  > >
  > 
  > This was not an issue with previous versions of R that I have used, 
including 3.3.3.
  > 
  > Any suggestions? Is this a known bug with 3.4.1?

Thank you, Peter!

I can confirm what you are seeing (on Linux) in R version 3.4.0,
3.4.1, and "R devel", and also that this had worked w/o a
problem in earlier versions of R, where I've looked at
R version 3.3.3 and 3.2.5.

I do think this is a bug, but it was not known till now.

For ease of use, I attach the two R files to easily reproduce.
Note I use  writeLines() instead of print() as its output is "nicer".

Best regards,
Martin Maechler, ETH Zurich


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


Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Martin Maechler
> Martin Maechler 
> on Wed, 23 Aug 2017 09:10:20 +0200 writes:

> Peter Bosa 
> on Tue, 22 Aug 2017 14:39:50 + writes:

>> Hello, I've noticed the following error using repeat{} / break in R 
3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit environments).
>> When running a repeat function, the break command causes an error 
message if the repeat command refers to code within a file, but does not 
produce an error if the code is contained within the repeat{} command.

>> Hello, I've noticed the following error using repeat{} / break in R 
3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit environments).
>> 
>> When running a repeat function, the break command causes an error 
message if the repeat command refers to code within a file, but does not 
produce an error if the code is contained within the repeat{} command.
>> 
>> For example, the following code runs fine:
>> 
>> x <- 1
>> y <- 5
>> 
>> repeat {
>> if(x < y) {
>> print("No Break Dance :-(")
>> x = x + 1
>> } else {
>> print("Break Dance!")
>> break
>> }
>> }
>> 
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "Break Dance!"
>> >
>> 
>> However, if I take the loop contents of the repeat{} function, and save 
them to a file (breakTest.R) that contains the following:
>> 
>> if(x < y) {
>> print("No Break Dance :-(")
>> x = x + 1
>> } else {
>> print("Break Dance!")
>> break
>> }
>> 
>> And then run the following code:
>> 
>> x <- 1
>> y <- 5
>> 
>> repeat{
>> source("./breakTest.R")
>> }
>> 
>> I get the following error:
>> 
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "No Break Dance :("
>> [1] "Break Dance!"
>> Error in eval(ei, envir) : no loop for break/next, jumping to top level
>> >
>> 
>> This was not an issue with previous versions of R that I have used, 
including 3.3.3.
>> 
>> Any suggestions? Is this a known bug with 3.4.1?

> Thank you, Peter!

> I can confirm what you are seeing (on Linux) in R version 3.4.0,
> 3.4.1, and "R devel", and also that this had worked w/o a
> problem in earlier versions of R, where I've looked at
> R version 3.3.3 and 3.2.5.

> I do think this is a bug, but it was not known till now.

> For ease of use, I attach the two R files to easily reproduce.
> Note I use  writeLines() instead of print() as its output is "nicer".

> Best regards,
> Martin Maechler, ETH Zurich

Trying again with the two attachment.  Yes, I of all people (!!)
should know that they must have an allowed MIME type; in this
case  text/plain !

Martin

## see ./break-source_R341.R
if(x < y) {
  writeLines("No Break Dance :-(")
  x <- x + 1
} else {
  writeLines("Break Dance!")
  break
}
## From: Peter Bosa 
## To: "R-devel@r-project.org" 
## Subject: [Rd] Possible repeat{} / break function bug in R 3.4.1
## Date: Tue, 22 Aug 2017 14:39:50 +

## Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).

## When running a repeat function, the break command causes an error message if 
the repeat command refers to code within a file, but does not produce an error 
if the code is contained within the repeat{} command.

## For example, the following code runs fine:

x <- 1
y <- 5
repeat {
  if(x < y) {
writeLines("No Break Dance :-(")
x <- x + 1
  } else {
writeLines("Break Dance!")
break
  }
}
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## >

## However, if I take the loop contents of the repeat{} function, and save
## them to a file (breakTest.R) that contains the following:
## ^^^
##__SEE THAT FILE__
## if(x < y) {
##   writeLines("No Break Dance :-(")
##   x = x + 1
## } else {
##   writeLines("Break Dance!")
##   break
## }

## And then run the following code:

x <- 1
y <- 5
repeat{
  source("./breakTest.R")
}
cat("successfully finished\n")

## I get the following error:

## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## Error in eval(ei, envir) : no loop for break/next, jumping to top level
## 


## This was not an issue with previous versions of R that I have used, 
including 3.3.3.

## MM: It does work in R 3.3.3, indeed
## --  it fails in R 3.4.0 and later


## Any suggestions? Is this a known bug with 3.4.1?

## Cheers-
## Peter


## 
## peter bosa
## metro
##

Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Lionel Henry
I don't think that's a bug. source() uses eval(), and eval() creates a
new function-like context frame. In a way expecting `break` to work
inside source() is like expecting `break` to cross stack frames:

my_break <- function() break
repeat(my_break())

Lionel


> On 23 août 2017, at 09:17, Martin Maechler  wrote:
> 
>> Martin Maechler 
>>on Wed, 23 Aug 2017 09:10:20 +0200 writes:
> 
>> Peter Bosa 
>>on Tue, 22 Aug 2017 14:39:50 + writes:
> 
>>> Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
>>> running on Windows 10 and Windows Server 2008 (both 64-bit environments).
>>> When running a repeat function, the break command causes an error message 
>>> if the repeat command refers to code within a file, but does not produce an 
>>> error if the code is contained within the repeat{} command.
> 
>>> Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
>>> running on Windows 10 and Windows Server 2008 (both 64-bit environments).
>>> 
>>> When running a repeat function, the break command causes an error message 
>>> if the repeat command refers to code within a file, but does not produce an 
>>> error if the code is contained within the repeat{} command.
>>> 
>>> For example, the following code runs fine:
>>> 
>>> x <- 1
>>> y <- 5
>>> 
>>> repeat {
>>> if(x < y) {
>>> print("No Break Dance :-(")
>>> x = x + 1
>>> } else {
>>> print("Break Dance!")
>>> break
>>> }
>>> }
>>> 
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "Break Dance!"
 
>>> 
>>> However, if I take the loop contents of the repeat{} function, and save 
>>> them to a file (breakTest.R) that contains the following:
>>> 
>>> if(x < y) {
>>> print("No Break Dance :-(")
>>> x = x + 1
>>> } else {
>>> print("Break Dance!")
>>> break
>>> }
>>> 
>>> And then run the following code:
>>> 
>>> x <- 1
>>> y <- 5
>>> 
>>> repeat{
>>> source("./breakTest.R")
>>> }
>>> 
>>> I get the following error:
>>> 
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "No Break Dance :("
>>> [1] "Break Dance!"
>>> Error in eval(ei, envir) : no loop for break/next, jumping to top level
 
>>> 
>>> This was not an issue with previous versions of R that I have used, 
>>> including 3.3.3.
>>> 
>>> Any suggestions? Is this a known bug with 3.4.1?
> 
>> Thank you, Peter!
> 
>> I can confirm what you are seeing (on Linux) in R version 3.4.0,
>> 3.4.1, and "R devel", and also that this had worked w/o a
>> problem in earlier versions of R, where I've looked at
>> R version 3.3.3 and 3.2.5.
> 
>> I do think this is a bug, but it was not known till now.
> 
>> For ease of use, I attach the two R files to easily reproduce.
>> Note I use  writeLines() instead of print() as its output is "nicer".
> 
>> Best regards,
>> Martin Maechler, ETH Zurich
> 
> Trying again with the two attachment.  Yes, I of all people (!!)
> should know that they must have an allowed MIME type; in this
> case  text/plain !
> 
> Martin
> 
> ## see ./break-source_R341.R
> if(x < y) {
>  writeLines("No Break Dance :-(")
>  x <- x + 1
> } else {
>  writeLines("Break Dance!")
>  break
> }
> ## From: Peter Bosa 
> ## To: "R-devel@r-project.org" 
> ## Subject: [Rd] Possible repeat{} / break function bug in R 3.4.1
> ## Date: Tue, 22 Aug 2017 14:39:50 +
> 
> ## Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
> running on Windows 10 and Windows Server 2008 (both 64-bit environments).
> 
> ## When running a repeat function, the break command causes an error message 
> if the repeat command refers to code within a file, but does not produce an 
> error if the code is contained within the repeat{} command.
> 
> ## For example, the following code runs fine:
> 
> x <- 1
> y <- 5
> repeat {
>  if(x < y) {
>writeLines("No Break Dance :-(")
>x <- x + 1
>  } else {
>writeLines("Break Dance!")
>break
>  }
> }
> ## No Break Dance :(
> ## No Break Dance :(
> ## No Break Dance :(
> ## No Break Dance :(
> ## No Break Dance :(
> ## Break Dance!
> ## >
> 
> ## However, if I take the loop contents of the repeat{} function, and save
> ## them to a file (breakTest.R) that contains the following:
> ## ^^^
> ##__SEE THAT FILE__
> ## if(x < y) {
> ##   writeLines("No Break Dance :-(")
> ##   x = x + 1
> ## } else {
> ##   writeLines("Break Dance!")
> ##   break
> ## }
> 
> ## And then run the following code:
> 
> x <- 1
> y <- 5
> repeat{
>  source("./breakTest.R")
> }
> cat("successfully finished\n")
> 
> ## I get the following error:
> 
> ## No Break Dance :(
> ## No Break Dance :(
> ## No Break Dance :(
> ## No Break Dance :(
> ## No Break Dance :(
> ## Break Dance!
> ## Error in eval(ei, envir) : no loop for break/next, jumping to top level
> ## 
> 
> 
> ## This was not an issu

Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Tomas Kalibera

It is a bug in the byte-code compiler. I will fix
Tomas

On 08/23/2017 09:22 AM, Lionel Henry wrote:

I don't think that's a bug. source() uses eval(), and eval() creates a
new function-like context frame. In a way expecting `break` to work
inside source() is like expecting `break` to cross stack frames:

 my_break <- function() break
 repeat(my_break())

Lionel



On 23 août 2017, at 09:17, Martin Maechler  wrote:


Martin Maechler 
on Wed, 23 Aug 2017 09:10:20 +0200 writes:
Peter Bosa 
on Tue, 22 Aug 2017 14:39:50 + writes:

Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).
When running a repeat function, the break command causes an error message if 
the repeat command refers to code within a file, but does not produce an error 
if the code is contained within the repeat{} command.
Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).

When running a repeat function, the break command causes an error message if 
the repeat command refers to code within a file, but does not produce an error 
if the code is contained within the repeat{} command.

For example, the following code runs fine:

x <- 1
y <- 5

repeat {
if(x < y) {
print("No Break Dance :-(")
x = x + 1
} else {
print("Break Dance!")
break
}
}

[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "Break Dance!"
However, if I take the loop contents of the repeat{} function, and save them to 
a file (breakTest.R) that contains the following:

if(x < y) {
print("No Break Dance :-(")
x = x + 1
} else {
print("Break Dance!")
break
}

And then run the following code:

x <- 1
y <- 5

repeat{
source("./breakTest.R")
}

I get the following error:

[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "Break Dance!"
Error in eval(ei, envir) : no loop for break/next, jumping to top level
This was not an issue with previous versions of R that I have used, including 
3.3.3.

Any suggestions? Is this a known bug with 3.4.1?

Thank you, Peter!
I can confirm what you are seeing (on Linux) in R version 3.4.0,
3.4.1, and "R devel", and also that this had worked w/o a
problem in earlier versions of R, where I've looked at
R version 3.3.3 and 3.2.5.
I do think this is a bug, but it was not known till now.
For ease of use, I attach the two R files to easily reproduce.
Note I use  writeLines() instead of print() as its output is "nicer".
Best regards,
Martin Maechler, ETH Zurich

Trying again with the two attachment.  Yes, I of all people (!!)
should know that they must have an allowed MIME type; in this
case  text/plain !

Martin

## see ./break-source_R341.R
if(x < y) {
  writeLines("No Break Dance :-(")
  x <- x + 1
} else {
  writeLines("Break Dance!")
  break
}
## From: Peter Bosa 
## To: "R-devel@r-project.org" 
## Subject: [Rd] Possible repeat{} / break function bug in R 3.4.1
## Date: Tue, 22 Aug 2017 14:39:50 +

## Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).

## When running a repeat function, the break command causes an error message if 
the repeat command refers to code within a file, but does not produce an error 
if the code is contained within the repeat{} command.

## For example, the following code runs fine:

x <- 1
y <- 5
repeat {
  if(x < y) {
writeLines("No Break Dance :-(")
x <- x + 1
  } else {
writeLines("Break Dance!")
break
  }
}
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## >

## However, if I take the loop contents of the repeat{} function, and save
## them to a file (breakTest.R) that contains the following:
## ^^^
##__SEE THAT FILE__
## if(x < y) {
##   writeLines("No Break Dance :-(")
##   x = x + 1
## } else {
##   writeLines("Break Dance!")
##   break
## }

## And then run the following code:

x <- 1
y <- 5
repeat{
  source("./breakTest.R")
}
cat("successfully finished\n")

## I get the following error:

## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## Error in eval(ei, envir) : no loop for break/next, jumping to top level
## 


## This was not an issue with previous versions of R that I have used, 
including 3.3.3.

## MM: It does work in R 3.3.3, indeed
## --  it fails in R 3.4.0 and later


## Any suggestions? Is this a known bug with 3.4.1?

## Cheers-
## Peter


## 
## peter bosa
## metro
## modeling services
## 600 ne grand ave
## portland, or  97232

## peter.b...@oregonmetro.gov

Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Lionel Henry
oops, I should have tried it:

expr <- quote(break)
repeat(eval(expr))


So eval() has hybrid semantics where `break` has more reach than
return(), weird.

expr <- quote(return())
repeat(eval(expr))  # infloop

Lionel


> On 23 août 2017, at 09:24, Tomas Kalibera  wrote:
> 
> It is a bug in the byte-code compiler. I will fix
> Tomas
> 
> On 08/23/2017 09:22 AM, Lionel Henry wrote:
>> I don't think that's a bug. source() uses eval(), and eval() creates a
>> new function-like context frame. In a way expecting `break` to work
>> inside source() is like expecting `break` to cross stack frames:
>> 
>> my_break <- function() break
>> repeat(my_break())
>> 
>> Lionel
>> 
>> 
>>> On 23 août 2017, at 09:17, Martin Maechler  
>>> wrote:
>>> 
 Martin Maechler 
on Wed, 23 Aug 2017 09:10:20 +0200 writes:
 Peter Bosa 
on Tue, 22 Aug 2017 14:39:50 + writes:
> Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
> running on Windows 10 and Windows Server 2008 (both 64-bit environments).
> When running a repeat function, the break command causes an error message 
> if the repeat command refers to code within a file, but does not produce 
> an error if the code is contained within the repeat{} command.
> Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
> running on Windows 10 and Windows Server 2008 (both 64-bit environments).
> 
> When running a repeat function, the break command causes an error message 
> if the repeat command refers to code within a file, but does not produce 
> an error if the code is contained within the repeat{} command.
> 
> For example, the following code runs fine:
> 
> x <- 1
> y <- 5
> 
> repeat {
> if(x < y) {
> print("No Break Dance :-(")
> x = x + 1
> } else {
> print("Break Dance!")
> break
> }
> }
> 
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "Break Dance!"
> However, if I take the loop contents of the repeat{} function, and save 
> them to a file (breakTest.R) that contains the following:
> 
> if(x < y) {
> print("No Break Dance :-(")
> x = x + 1
> } else {
> print("Break Dance!")
> break
> }
> 
> And then run the following code:
> 
> x <- 1
> y <- 5
> 
> repeat{
> source("./breakTest.R")
> }
> 
> I get the following error:
> 
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "Break Dance!"
> Error in eval(ei, envir) : no loop for break/next, jumping to top level
> This was not an issue with previous versions of R that I have used, 
> including 3.3.3.
> 
> Any suggestions? Is this a known bug with 3.4.1?
 Thank you, Peter!
 I can confirm what you are seeing (on Linux) in R version 3.4.0,
 3.4.1, and "R devel", and also that this had worked w/o a
 problem in earlier versions of R, where I've looked at
 R version 3.3.3 and 3.2.5.
 I do think this is a bug, but it was not known till now.
 For ease of use, I attach the two R files to easily reproduce.
 Note I use  writeLines() instead of print() as its output is "nicer".
 Best regards,
 Martin Maechler, ETH Zurich
>>> Trying again with the two attachment.  Yes, I of all people (!!)
>>> should know that they must have an allowed MIME type; in this
>>> case  text/plain !
>>> 
>>> Martin
>>> 
>>> ## see ./break-source_R341.R
>>> if(x < y) {
>>>  writeLines("No Break Dance :-(")
>>>  x <- x + 1
>>> } else {
>>>  writeLines("Break Dance!")
>>>  break
>>> }
>>> ## From: Peter Bosa 
>>> ## To: "R-devel@r-project.org" 
>>> ## Subject: [Rd] Possible repeat{} / break function bug in R 3.4.1
>>> ## Date: Tue, 22 Aug 2017 14:39:50 +
>>> 
>>> ## Hello, I've noticed the following error using repeat{} / break in R 
>>> 3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit 
>>> environments).
>>> 
>>> ## When running a repeat function, the break command causes an error 
>>> message if the repeat command refers to code within a file, but does not 
>>> produce an error if the code is contained within the repeat{} command.
>>> 
>>> ## For example, the following code runs fine:
>>> 
>>> x <- 1
>>> y <- 5
>>> repeat {
>>>  if(x < y) {
>>>writeLines("No Break Dance :-(")
>>>x <- x + 1
>>>  } else {
>>>writeLines("Break Dance!")
>>>break
>>>  }
>>> }
>>> ## No Break Dance :(
>>> ## No Break Dance :(
>>> ## No Break Dance :(
>>> ## No Break Dance :(
>>> ## No Break Dance :(
>>> ## Break Dance!
>>> ## >
>>> 
>>> ## However, if I take the loop contents of the repeat{} function, and save
>>> ## them to a file (breakTest.R) that contains the following:
>

Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Tomas Kalibera

Fixed in 73112.

If you needed to run this code in unpatched versions of R, you can 
disable the problematic compiler optimization in the loop for instance 
by adding "eval(NULL)" to the body of the loop. However, please do not 
forget to remove this for future versions of R and specifically do not 
assume this would turn off a particular compiler optimization in future 
versions.


Best
Tomas




On 08/23/2017 09:24 AM, Tomas Kalibera wrote:

It is a bug in the byte-code compiler. I will fix
Tomas

On 08/23/2017 09:22 AM, Lionel Henry wrote:

I don't think that's a bug. source() uses eval(), and eval() creates a
new function-like context frame. In a way expecting `break` to work
inside source() is like expecting `break` to cross stack frames:

 my_break <- function() break
 repeat(my_break())

Lionel


On 23 août 2017, at 09:17, Martin Maechler 
 wrote:



Martin Maechler 
on Wed, 23 Aug 2017 09:10:20 +0200 writes:
Peter Bosa 
on Tue, 22 Aug 2017 14:39:50 + writes:
Hello, I've noticed the following error using repeat{} / break in 
R 3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit 
environments).
When running a repeat function, the break command causes an error 
message if the repeat command refers to code within a file, but 
does not produce an error if the code is contained within the 
repeat{} command.
Hello, I've noticed the following error using repeat{} / break in 
R 3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit 
environments).


When running a repeat function, the break command causes an error 
message if the repeat command refers to code within a file, but 
does not produce an error if the code is contained within the 
repeat{} command.


For example, the following code runs fine:

x <- 1
y <- 5

repeat {
if(x < y) {
print("No Break Dance :-(")
x = x + 1
} else {
print("Break Dance!")
break
}
}

[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "Break Dance!"
However, if I take the loop contents of the repeat{} function, and 
save them to a file (breakTest.R) that contains the following:


if(x < y) {
print("No Break Dance :-(")
x = x + 1
} else {
print("Break Dance!")
break
}

And then run the following code:

x <- 1
y <- 5

repeat{
source("./breakTest.R")
}

I get the following error:

[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "Break Dance!"
Error in eval(ei, envir) : no loop for break/next, jumping to top 
level
This was not an issue with previous versions of R that I have 
used, including 3.3.3.


Any suggestions? Is this a known bug with 3.4.1?

Thank you, Peter!
I can confirm what you are seeing (on Linux) in R version 3.4.0,
3.4.1, and "R devel", and also that this had worked w/o a
problem in earlier versions of R, where I've looked at
R version 3.3.3 and 3.2.5.
I do think this is a bug, but it was not known till now.
For ease of use, I attach the two R files to easily reproduce.
Note I use  writeLines() instead of print() as its output is "nicer".
Best regards,
Martin Maechler, ETH Zurich

Trying again with the two attachment.  Yes, I of all people (!!)
should know that they must have an allowed MIME type; in this
case  text/plain !

Martin

## see ./break-source_R341.R
if(x < y) {
  writeLines("No Break Dance :-(")
  x <- x + 1
} else {
  writeLines("Break Dance!")
  break
}
## From: Peter Bosa 
## To: "R-devel@r-project.org" 
## Subject: [Rd] Possible repeat{} / break function bug in R 3.4.1
## Date: Tue, 22 Aug 2017 14:39:50 +

## Hello, I've noticed the following error using repeat{} / break in 
R 3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit 
environments).


## When running a repeat function, the break command causes an error 
message if the repeat command refers to code within a file, but does 
not produce an error if the code is contained within the repeat{} 
command.


## For example, the following code runs fine:

x <- 1
y <- 5
repeat {
  if(x < y) {
writeLines("No Break Dance :-(")
x <- x + 1
  } else {
writeLines("Break Dance!")
break
  }
}
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## >

## However, if I take the loop contents of the repeat{} function, 
and save

## them to a file (breakTest.R) that contains the following:
## ^^^
##__SEE THAT FILE__
## if(x < y) {
##   writeLines("No Break Dance :-(")
##   x = x + 1
## } else {
##   writeLines("Break Dance!")
##   break
## }

## And then run the following code:

x <- 1
y <- 5
repeat{
  source("./breakTest.R")
}
cat("successfully finished\n")

## I get the following error:

## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## Error in eval(ei, envir) : no loop for break/next, jumping to top 
leve

Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Tomas Kalibera


return can be used to set the return value of an expression evaluated by 
"eval"


expr <- quote(if (x) return(1) else return(2))
x <- FALSE
eval(expr) #2

Tomas

On 08/23/2017 09:46 AM, Lionel Henry wrote:

oops, I should have tried it:

 expr <- quote(break)
 repeat(eval(expr))


So eval() has hybrid semantics where `break` has more reach than
return(), weird.

 expr <- quote(return())
 repeat(eval(expr))  # infloop

Lionel



On 23 août 2017, at 09:24, Tomas Kalibera  wrote:

It is a bug in the byte-code compiler. I will fix
Tomas

On 08/23/2017 09:22 AM, Lionel Henry wrote:

I don't think that's a bug. source() uses eval(), and eval() creates a
new function-like context frame. In a way expecting `break` to work
inside source() is like expecting `break` to cross stack frames:

 my_break <- function() break
 repeat(my_break())

Lionel



On 23 août 2017, at 09:17, Martin Maechler  wrote:


Martin Maechler 
on Wed, 23 Aug 2017 09:10:20 +0200 writes:
Peter Bosa 
on Tue, 22 Aug 2017 14:39:50 + writes:

Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).
When running a repeat function, the break command causes an error message if 
the repeat command refers to code within a file, but does not produce an error 
if the code is contained within the repeat{} command.
Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).

When running a repeat function, the break command causes an error message if 
the repeat command refers to code within a file, but does not produce an error 
if the code is contained within the repeat{} command.

For example, the following code runs fine:

x <- 1
y <- 5

repeat {
if(x < y) {
print("No Break Dance :-(")
x = x + 1
} else {
print("Break Dance!")
break
}
}

[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "Break Dance!"
However, if I take the loop contents of the repeat{} function, and save them to 
a file (breakTest.R) that contains the following:

if(x < y) {
print("No Break Dance :-(")
x = x + 1
} else {
print("Break Dance!")
break
}

And then run the following code:

x <- 1
y <- 5

repeat{
source("./breakTest.R")
}

I get the following error:

[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "No Break Dance :("
[1] "Break Dance!"
Error in eval(ei, envir) : no loop for break/next, jumping to top level
This was not an issue with previous versions of R that I have used, including 
3.3.3.

Any suggestions? Is this a known bug with 3.4.1?

Thank you, Peter!
I can confirm what you are seeing (on Linux) in R version 3.4.0,
3.4.1, and "R devel", and also that this had worked w/o a
problem in earlier versions of R, where I've looked at
R version 3.3.3 and 3.2.5.
I do think this is a bug, but it was not known till now.
For ease of use, I attach the two R files to easily reproduce.
Note I use  writeLines() instead of print() as its output is "nicer".
Best regards,
Martin Maechler, ETH Zurich

Trying again with the two attachment.  Yes, I of all people (!!)
should know that they must have an allowed MIME type; in this
case  text/plain !

Martin

## see ./break-source_R341.R
if(x < y) {
  writeLines("No Break Dance :-(")
  x <- x + 1
} else {
  writeLines("Break Dance!")
  break
}
## From: Peter Bosa 
## To: "R-devel@r-project.org" 
## Subject: [Rd] Possible repeat{} / break function bug in R 3.4.1
## Date: Tue, 22 Aug 2017 14:39:50 +

## Hello, I've noticed the following error using repeat{} / break in R 3.4.1 
running on Windows 10 and Windows Server 2008 (both 64-bit environments).

## When running a repeat function, the break command causes an error message if 
the repeat command refers to code within a file, but does not produce an error 
if the code is contained within the repeat{} command.

## For example, the following code runs fine:

x <- 1
y <- 5
repeat {
  if(x < y) {
writeLines("No Break Dance :-(")
x <- x + 1
  } else {
writeLines("Break Dance!")
break
  }
}
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## >

## However, if I take the loop contents of the repeat{} function, and save
## them to a file (breakTest.R) that contains the following:
## ^^^
##__SEE THAT FILE__
## if(x < y) {
##   writeLines("No Break Dance :-(")
##   x = x + 1
## } else {
##   writeLines("Break Dance!")
##   break
## }

## And then run the following code:

x <- 1
y <- 5
repeat{
  source("./breakTest.R")
}
cat("successfully finished\n")

## I get the following error:

## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## No Break Dance :(
## Break Dance!
## Error in eval(ei, envir) : no loo

[Rd] bugs in documentation of stats::stl

2017-08-23 Thread Mark van der Loo
Dear list, R-core,


The documentation of stats::stl explicitly refers to the paper by
Cleveland[1] to explain the parameters. However, the description is
confusing, with two descriptions seeming to refer to the same parameter in
the paper.

s.window: [...] the loess window for seasonal extraction, which should be
odd and at least 7, according to Cleveland et al

--> The phrase 'odd and at least 7' refers to Cleveland's parameter n_(s),
section 3.5 of [1].

Confusing: Cleveland calls this 'seasonal smoothing', not extraction.


l.window:  the span (in lags) of the loess window of the low-pass filter
used for each subseries.[...]

--> The description 'low-pass filter used for each subseries' also seems to
correspond to Cleveland's parameter n_(s), in step two of the algorithm in
the reference. (section 2.2 of [1]).

Confusing: Cleveland does not apply a low-pass filter to each subseries[2].
The subseries are reconstructed to a single series and after that a
low-pass filter is applied (step 3 of the algorithm in section 2.2 of [1])


So what should it be? A literal reference to Cleveland's n_(s), n_(l), and
n_(t) would be really helpful here.



Thank you,
Best,
Mark


[1] https://www.wessa.net/download/stl.pdf
[2] well, technically he does in step 2 of the algorithm, but it is not
called a low-pass filter in the paper.

[[alternative HTML version deleted]]

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


Re: [Rd] MASS:::dropterm.glm() and MASS:::addterm.glm() should use ... for extractAIC()

2017-08-23 Thread Marc Girondot via R-devel

Hi,
I have sent this message to this list the July, 7th. It was about a 
problem in MASS package.

Until now there is no change in the devel version.
As the problem occurs in a package and not in the R-core, I don't know 
if the message should have been sent here. Anyway, I have added a copy 
to Pr Ripley.

I hope it could have been fixed.
Sincerely
Marc

Le 09/07/2017 à 16:05, Marc Girondot via R-devel a écrit :
Here is a change required from MASS:::dropterm.glm() and 
MASS:::addterm.glm().


Thanks

Marc


The stepAIC() function from package MASS uses extractAIC() to get the 
AIC from a model.

Several methods exist:
extractAIC.glm() for example, some in MASS packages and some in stats 
package.


The parameters for extractAIC() are:
fit, scale, k = 2, ...

The ... are not used in most of the extractAIC.xxx() methods, from 
example in stats:::extractAIC.glm() or MASS:::extractAIC.loglm() but 
its presence could be necessary if extractAIC() is changed to use for 
example to use AICc rather than AIC.


Within stepAIC(), extractAIC() uses always the ... parameter. So all 
is ok for that.


However, stepAIC() uses dropterm() or addterm().

Within MASS:::dropterm.glm() and MASS:::addterm.glm(), extractAIC() is 
also used but without the ... parameter.


It prevents to use new version of extractAIC() that could use this 
parameter.


The solution is simple:
In MASS:::dropterm.glm(), line 60 and MASS:::addterm.glm(), line 84:
aic <- aic + (extractAIC(object, k = k)[2L] - aic[1L])
must be changed to
aic <- aic + (extractAIC(object, k = k, ...)[2L] - aic[1L])

Other dropterm.xxx() and addterm.xxx() do not suffer this problem.

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



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

Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

2017-08-23 Thread Peter Bosa
Thank you, Gentlemen...much appreciated!


peter bosa
metro
transportation research and modeling services
600 ne grand ave
portland, or  97232
 
peter.b...@oregonmetro.gov
503.797.1771
 
metro | making a great place
www.oregonmetro.gov

From: Tomas Kalibera 
Sent: Wednesday, August 23, 2017 12:54 AM
To: Peter Bosa
Cc: Lionel Henry; Martin Maechler; R-devel@r-project.org
Subject: Re: [Rd] Possible repeat{} / break function bug in R 3.4.1

Fixed in 73112.

If you needed to run this code in unpatched versions of R, you can
disable the problematic compiler optimization in the loop for instance
by adding "eval(NULL)" to the body of the loop. However, please do not
forget to remove this for future versions of R and specifically do not
assume this would turn off a particular compiler optimization in future
versions.

Best
Tomas




On 08/23/2017 09:24 AM, Tomas Kalibera wrote:
> It is a bug in the byte-code compiler. I will fix
> Tomas
>
> On 08/23/2017 09:22 AM, Lionel Henry wrote:
>> I don't think that's a bug. source() uses eval(), and eval() creates a
>> new function-like context frame. In a way expecting `break` to work
>> inside source() is like expecting `break` to cross stack frames:
>>
>>  my_break <- function() break
>>  repeat(my_break())
>>
>> Lionel
>>
>>
>>> On 23 août 2017, at 09:17, Martin Maechler
>>>  wrote:
>>>
 Martin Maechler 
 on Wed, 23 Aug 2017 09:10:20 +0200 writes:
 Peter Bosa 
 on Tue, 22 Aug 2017 14:39:50 + writes:
> Hello, I've noticed the following error using repeat{} / break in
> R 3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit
> environments).
> When running a repeat function, the break command causes an error
> message if the repeat command refers to code within a file, but
> does not produce an error if the code is contained within the
> repeat{} command.
> Hello, I've noticed the following error using repeat{} / break in
> R 3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit
> environments).
>
> When running a repeat function, the break command causes an error
> message if the repeat command refers to code within a file, but
> does not produce an error if the code is contained within the
> repeat{} command.
>
> For example, the following code runs fine:
>
> x <- 1
> y <- 5
>
> repeat {
> if(x < y) {
> print("No Break Dance :-(")
> x = x + 1
> } else {
> print("Break Dance!")
> break
> }
> }
>
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "Break Dance!"
> However, if I take the loop contents of the repeat{} function, and
> save them to a file (breakTest.R) that contains the following:
>
> if(x < y) {
> print("No Break Dance :-(")
> x = x + 1
> } else {
> print("Break Dance!")
> break
> }
>
> And then run the following code:
>
> x <- 1
> y <- 5
>
> repeat{
> source("./breakTest.R")
> }
>
> I get the following error:
>
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "No Break Dance :("
> [1] "Break Dance!"
> Error in eval(ei, envir) : no loop for break/next, jumping to top
> level
> This was not an issue with previous versions of R that I have
> used, including 3.3.3.
>
> Any suggestions? Is this a known bug with 3.4.1?
 Thank you, Peter!
 I can confirm what you are seeing (on Linux) in R version 3.4.0,
 3.4.1, and "R devel", and also that this had worked w/o a
 problem in earlier versions of R, where I've looked at
 R version 3.3.3 and 3.2.5.
 I do think this is a bug, but it was not known till now.
 For ease of use, I attach the two R files to easily reproduce.
 Note I use  writeLines() instead of print() as its output is "nicer".
 Best regards,
 Martin Maechler, ETH Zurich
>>> Trying again with the two attachment.  Yes, I of all people (!!)
>>> should know that they must have an allowed MIME type; in this
>>> case  text/plain !
>>>
>>> Martin
>>>
>>> ## see ./break-source_R341.R
>>> if(x < y) {
>>>   writeLines("No Break Dance :-(")
>>>   x <- x + 1
>>> } else {
>>>   writeLines("Break Dance!")
>>>   break
>>> }
>>> ## From: Peter Bosa 
>>> ## To: "R-devel@r-project.org" 
>>> ## Subject: [Rd] Possible repeat{} / break function bug in R 3.4.1
>>> ## Date: Tue, 22 Aug 2017 14:39:50 +
>>>
>>> ## Hello, I've noticed the following error using repeat{} / break in
>>> R 3.4.1 running on Windows 10 and Windows Server 2008 (both 64-bit
>>> environments).
>>>
>>> ## When running a repeat function, the break command causes an error
>