issue with promises for time parameter of rep()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

issue with promises for time parameter of rep()

Homer White
Greetings,

The following is based on a question I raised on Stackoverflow:

https://stackoverflow.com/questions/46280120/calling-printls-str-in-function-affect-behavior-of-rep/46283979#46283979

Start a new R session with an empty Global Env.  Then define:

f <- function(n) {
  print(ls.str())
  rep("hello", times = n)
}

Now run:

f(x)

Instead of getting the expected "object 'x' not found" error, you get:

n : <missing>[1] "hello"

It was suggested that I file the issue here as a possible bug.


Regards,

Homer

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: issue with promises for time parameter of rep()

Lionel Henry
Here is the same issue with closures:

    g <- function(n) {
      missing(n)
    }
    f <- function(n, force) {
      if (force) {
        tryCatch(n, error = function(...) NULL)
      }
      g(n)
    }

    g(`_x`)
    #> [1] FALSE

    f(`_x`, force = FALSE)
    #> [1] FALSE

    f(`_x`, force = TRUE)
    #> [1] TRUE

Lionel

> On 18 sept. 2017, at 19:06, Homer White <[hidden email]> wrote:
>
> Greetings,
>
> The following is based on a question I raised on Stackoverflow:
>
> https://stackoverflow.com/questions/46280120/calling-printls-str-in-function-affect-behavior-of-rep/46283979#46283979
>
> Start a new R session with an empty Global Env.  Then define:
>
> f <- function(n) {
>  print(ls.str())
>  rep("hello", times = n)
> }
>
> Now run:
>
> f(x)
>
> Instead of getting the expected "object 'x' not found" error, you get:
>
> n : <missing>[1] "hello"
>
> It was suggested that I file the issue here as a possible bug.
>
>
> Regards,
>
> Homer
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: issue with promises for time parameter of rep()

luke-tierney
In reply to this post by Homer White
Thanks. Fixed in R-devel and R-patched. This now gives

f <- function(n) {
     print(ls.str())
     rep("hello", times = n)
}
f(n)
## n : <missing>
## Error in f(n) : object 'n' not found
## In addition: Warning message:
## In f(n) : restarting interrupted promise evaluation

Best,

luke

On Mon, 18 Sep 2017, Homer White wrote:

> Greetings,
>
> The following is based on a question I raised on Stackoverflow:
>
> https://stackoverflow.com/questions/46280120/calling-printls-str-in-function-affect-behavior-of-rep/46283979#46283979
>
> Start a new R session with an empty Global Env.  Then define:
>
> f <- function(n) {
>  print(ls.str())
>  rep("hello", times = n)
> }
>
> Now run:
>
> f(x)
>
> Instead of getting the expected "object 'x' not found" error, you get:
>
> n : <missing>[1] "hello"
>
> It was suggested that I file the issue here as a possible bug.
>
>
> Regards,
>
> Homer
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel